forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-standalone-loader.js
More file actions
73 lines (66 loc) · 1.73 KB
/
Copy pathbuild-standalone-loader.js
File metadata and controls
73 lines (66 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-require-imports */
const esbuild = require('esbuild');
const packageVersion = require('../package.json').version;
console.log('build standalone-loader: packageVersion=%s', packageVersion);
const enableAnalyze = process.env.ANALYZE === 'true';
const buildConfig = {
entryPoints: ['src/standalone-loader.ts'],
outfile: 'dist/standalone-loader.js',
metafile: enableAnalyze,
bundle: true,
target: ['chrome69'],
format: 'cjs',
sourcemap: true,
sourcesContent: true,
external: Object.keys(require('../package.json').dependencies),
define: {
process: JSON.stringify({
env: {
NODE_ENV: 'production',
STANDALONE: 'true',
},
}),
__PACKAGE_VERSION__: JSON.stringify(packageVersion),
},
minify: false,
minifyWhitespace: false,
minifyIdentifiers: false,
minifySyntax: false,
legalComments: 'external',
treeShaking: true,
};
// 执行脚本
(async () => {
try {
console.log('building cjs...');
const result = await esbuild.build({
...buildConfig,
});
if (result.errors.length > 0) {
throw result.errors;
}
if (result.warnings.length > 0) {
result.warnings.forEach((warnings) => {
console.warn(warnings);
});
}
const result2 = await esbuild.build({
...buildConfig,
outfile: buildConfig.outfile.replace(/\.js$/, '.esm.js'),
format: 'esm',
});
if (result2.errors.length > 0) {
throw result2.errors;
}
if (result2.warnings.length > 0) {
result2.warnings.forEach((warnings) => {
console.warn(warnings);
});
}
console.log('done');
} catch (e) {
console.error(e);
process.exit(1);
}
})();