mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
fix: pro plugin build
This commit is contained in:
parent
53f2ff4779
commit
abbe88e46c
@ -362,12 +362,21 @@ export async function buildProPluginServer(cwd: string, userConfig: UserConfig,
|
|||||||
// plugin-commercial build to a bundle
|
// plugin-commercial build to a bundle
|
||||||
const externalOptions = {
|
const externalOptions = {
|
||||||
external: [],
|
external: [],
|
||||||
noExternal: []
|
noExternal: [],
|
||||||
|
onSuccess: async () => {},
|
||||||
|
esbuildPlugins: [],
|
||||||
};
|
};
|
||||||
// other plugins build to a bundle just include plugin-commercial
|
// other plugins build to a bundle just include plugin-commercial
|
||||||
if (!cwd.includes(PLUGIN_COMMERCIAL)) {
|
if (!cwd.includes(PLUGIN_COMMERCIAL)) {
|
||||||
externalOptions.external = [/^[./]/];
|
externalOptions.external = [/^[./]/];
|
||||||
externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
|
externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
|
||||||
|
externalOptions.onSuccess = async () => {
|
||||||
|
const serverFiles = [path.join(cwd, target_dir, 'server', 'index.js')];
|
||||||
|
serverFiles.forEach((file) => {
|
||||||
|
obfuscate(file);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
externalOptions.esbuildPlugins = [pluginEsbuildCommercialInject];
|
||||||
}
|
}
|
||||||
|
|
||||||
// bundle all files、inject commercial code and obfuscate
|
// bundle all files、inject commercial code and obfuscate
|
||||||
@ -384,20 +393,14 @@ export async function buildProPluginServer(cwd: string, userConfig: UserConfig,
|
|||||||
sourcemap,
|
sourcemap,
|
||||||
outDir: path.join(cwd, target_dir, 'server'),
|
outDir: path.join(cwd, target_dir, 'server'),
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
...externalOptions,
|
|
||||||
skipNodeModulesBundle: true,
|
skipNodeModulesBundle: true,
|
||||||
tsconfig: tsconfig.path,
|
tsconfig: tsconfig.path,
|
||||||
loader: {
|
loader: {
|
||||||
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: 'copy' }), {}),
|
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: 'copy' }), {}),
|
||||||
'.json': 'copy',
|
'.json': 'copy',
|
||||||
},
|
},
|
||||||
esbuildPlugins: [pluginEsbuildCommercialInject],
|
|
||||||
onSuccess: async () => {
|
...externalOptions,
|
||||||
const serverFiles = [path.join(cwd, target_dir, 'server', 'index.js')];
|
|
||||||
serverFiles.forEach((file) => {
|
|
||||||
obfuscate(file);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
fs.removeSync(tsconfig.path);
|
fs.removeSync(tsconfig.path);
|
||||||
|
@ -14,34 +14,29 @@ export const obfuscate = (filePath: string) => {
|
|||||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||||
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, {
|
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, {
|
||||||
compact: true,
|
compact: true,
|
||||||
controlFlowFlattening: true,
|
controlFlowFlattening: false,
|
||||||
controlFlowFlatteningThreshold: 0.75,
|
deadCodeInjection: false,
|
||||||
deadCodeInjection: true,
|
|
||||||
deadCodeInjectionThreshold: 0.4,
|
|
||||||
debugProtection: false,
|
debugProtection: false,
|
||||||
debugProtectionInterval: 0,
|
debugProtectionInterval: 0,
|
||||||
disableConsoleOutput: true,
|
disableConsoleOutput: true,
|
||||||
identifierNamesGenerator: 'hexadecimal',
|
identifierNamesGenerator: 'hexadecimal',
|
||||||
log: false,
|
log: false,
|
||||||
numbersToExpressions: true,
|
numbersToExpressions: false,
|
||||||
renameGlobals: false,
|
renameGlobals: false,
|
||||||
selfDefending: true,
|
selfDefending: true,
|
||||||
simplify: true,
|
simplify: true,
|
||||||
splitStrings: true,
|
splitStrings: false,
|
||||||
splitStringsChunkLength: 10,
|
|
||||||
stringArray: true,
|
stringArray: true,
|
||||||
stringArrayCallsTransform: true,
|
stringArrayCallsTransform: false,
|
||||||
stringArrayCallsTransformThreshold: 0.75,
|
stringArrayEncoding: [],
|
||||||
stringArrayEncoding: ['base64'],
|
|
||||||
stringArrayIndexShift: true,
|
stringArrayIndexShift: true,
|
||||||
stringArrayRotate: true,
|
stringArrayRotate: true,
|
||||||
stringArrayShuffle: true,
|
stringArrayShuffle: true,
|
||||||
stringArrayWrappersCount: 2,
|
stringArrayWrappersCount: 1,
|
||||||
stringArrayWrappersChainedCalls: true,
|
stringArrayWrappersChainedCalls: true,
|
||||||
stringArrayWrappersParametersMaxCount: 4,
|
stringArrayWrappersParametersMaxCount: 2,
|
||||||
stringArrayWrappersType: 'function',
|
stringArrayWrappersType: 'variable',
|
||||||
stringArrayThreshold: 0.75,
|
stringArrayThreshold: 0.75,
|
||||||
transformObjectKeys: true,
|
|
||||||
unicodeEscapeSequence: false
|
unicodeEscapeSequence: false
|
||||||
});
|
});
|
||||||
fs.writeFileSync(filePath, obfuscationResult.getObfuscatedCode(), 'utf8');
|
fs.writeFileSync(filePath, obfuscationResult.getObfuscatedCode(), 'utf8');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user