๐Ÿ“ฆ theajack / webos

๐Ÿ“„ dev.js ยท 60 lines
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/*
 * @Author: chenzhongsheng
 * @Date: 2022-10-24 10:31:38
 * @Description: Coding something
 */
const { build } = require('esbuild');
const { resolve } = require('path');
const { yamlPlugin } = require('esbuild-plugin-yaml');
const { dtsPlugin } = require('esbuild-plugin-d.ts');

const outfile = resolve(__dirname, './dev/bundle.js');

let entry = resolve(__dirname, './dev/index.ts');

if (process.argv[2] === 'test') {
    entry = resolve(__dirname, './unit-test/index.ts');
}

build({
    entryPoints: [ entry ],
    // entryPoints: [resolve(__dirname, './dev/samples/alins/src/Main.js')],
    outfile,
    bundle: true,
    sourcemap: true,
    format: 'cjs',
    globalName: 'Webos',
    platform: 'browser',
    // plugins:
    //   format === 'cjs' || pkg.buildOptions?.enableNonBrowserBranches
    //     ? [nodePolyfills.default()]
    //     : undefined,
    // define: {
    //   __COMMIT__: '"dev"',
    //   __VERSION__: `"${pkg.version}"`,
    //   __DEV__: 'true',
    //   __TEST__: 'false',
    //   __BROWSER__: String(format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches),
    //   __GLOBAL__: String(format === 'global'),
    //   __ESM_BUNDLER__: String(format.includes('esm-bundler')),
    //   __ESM_BROWSER__: String(format.includes('esm-browser')),
    //   __NODE_JS__: String(format === 'cjs'),
    //   __SSR__: String(format === 'cjs' || format.includes('esm-bundler')),
    //   __COMPAT__: String(target === 'vue-compat'),
    //   __FEATURE_SUSPENSE__: 'true',
    //   __FEATURE_OPTIONS_API__: 'true',
    //   __FEATURE_PROD_DEVTOOLS__: 'false',
    // },
    plugins: [
        yamlPlugin(),
        dtsPlugin(),
    ],
    watch: {
        onRebuild (error) {
            if (!error) console.log(`rebuilt: ${outfile}`);
        },
    },
}).then(() => {
    console.log(`watching: ${outfile}`);
});