diff --git a/script/rollup.config.ts b/script/rollup.config.ts index 16b27d2..3984ad3 100644 --- a/script/rollup.config.ts +++ b/script/rollup.config.ts @@ -6,6 +6,7 @@ import esbuild from 'rollup-plugin-esbuild' import alias from '@rollup/plugin-alias' import json from '@rollup/plugin-json' import copy from 'rollup-plugin-copy' +import externals from 'rollup-plugin-node-externals' export default (env = 'production') => { const options: RollupOptions = { @@ -26,7 +27,7 @@ export default (env = 'production') => { exclude: /node_modules/, // default // watch: process.argv.includes('--watch'), // rollup 中有配置 sourceMap: false, // default - minify: process.env.NODE_ENV === 'production', + minify: env === 'production', target: 'es2017', // default, or 'es20XX', 'esnext' jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', @@ -34,6 +35,7 @@ export default (env = 'production') => { define: { __VERSION__: '"x.y.z"' }, + tsconfig: 'tsconfig.json', // default // Add extra loaders loaders: { // Add .json files support @@ -50,21 +52,10 @@ export default (env = 'production') => { }), copy({ targets: [{ src: join(__dirname, '../src/preload'), dest: join(__dirname, '../dist') }], - }) - ], - external: [ - 'crypto', - 'assert', - 'fs', - 'util', - 'os', - 'events', - 'child_process', - 'http', - 'https', - 'path', - 'electron', + }), + externals(), ], + external: ['electron'], } return options diff --git a/script/utils.ts b/script/utils.ts index 7bf4495..ecbdbea 100644 --- a/script/utils.ts +++ b/script/utils.ts @@ -1,17 +1,19 @@ import { get } from 'http' +import { green } from 'chalk' /** 轮询监听 vite 启动 */ export function waitOn(arg0: { port: string | number; interval?: number; }) { return new Promise(resolve => { const { port, interval = 149 } = arg0 + const url = `http://localhost:${port}` let counter = 0 const timer: NodeJS.Timer = setInterval(() => { - get(`http://localhost:${port}`, res => { + get(url, res => { clearInterval(timer) - console.log('[waitOn]', res.statusCode, res.statusMessage) + console.log('[waitOn]', green(`"${url}" are already responsive.`), `(${res.statusCode}: ${res.statusMessage})`) resolve(res.statusCode) }).on('error', err => { - console.log('[waitOn]', `counter:${counter++}`) + console.log('[waitOn]', `counter: ${counter++}`) }) }, interval) })