fix: rollup-plugin-esbuild 低版本报错

This commit is contained in:
草鞋没号 2021-02-18 14:45:20 +08:00
parent cbafc2c790
commit 48d5a92e6d
2 changed files with 11 additions and 18 deletions

View File

@ -6,6 +6,7 @@ import esbuild from 'rollup-plugin-esbuild'
import alias from '@rollup/plugin-alias' import alias from '@rollup/plugin-alias'
import json from '@rollup/plugin-json' import json from '@rollup/plugin-json'
import copy from 'rollup-plugin-copy' import copy from 'rollup-plugin-copy'
import externals from 'rollup-plugin-node-externals'
export default (env = 'production') => { export default (env = 'production') => {
const options: RollupOptions = { const options: RollupOptions = {
@ -26,7 +27,7 @@ export default (env = 'production') => {
exclude: /node_modules/, // default exclude: /node_modules/, // default
// watch: process.argv.includes('--watch'), // rollup 中有配置 // watch: process.argv.includes('--watch'), // rollup 中有配置
sourceMap: false, // default sourceMap: false, // default
minify: process.env.NODE_ENV === 'production', minify: env === 'production',
target: 'es2017', // default, or 'es20XX', 'esnext' target: 'es2017', // default, or 'es20XX', 'esnext'
jsxFactory: 'React.createElement', jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment', jsxFragment: 'React.Fragment',
@ -34,6 +35,7 @@ export default (env = 'production') => {
define: { define: {
__VERSION__: '"x.y.z"' __VERSION__: '"x.y.z"'
}, },
tsconfig: 'tsconfig.json', // default
// Add extra loaders // Add extra loaders
loaders: { loaders: {
// Add .json files support // Add .json files support
@ -50,21 +52,10 @@ export default (env = 'production') => {
}), }),
copy({ copy({
targets: [{ src: join(__dirname, '../src/preload'), dest: join(__dirname, '../dist') }], targets: [{ src: join(__dirname, '../src/preload'), dest: join(__dirname, '../dist') }],
}) }),
], externals(),
external: [
'crypto',
'assert',
'fs',
'util',
'os',
'events',
'child_process',
'http',
'https',
'path',
'electron',
], ],
external: ['electron'],
} }
return options return options

View File

@ -1,17 +1,19 @@
import { get } from 'http' import { get } from 'http'
import { green } from 'chalk'
/** 轮询监听 vite 启动 */ /** 轮询监听 vite 启动 */
export function waitOn(arg0: { port: string | number; interval?: number; }) { export function waitOn(arg0: { port: string | number; interval?: number; }) {
return new Promise(resolve => { return new Promise(resolve => {
const { port, interval = 149 } = arg0 const { port, interval = 149 } = arg0
const url = `http://localhost:${port}`
let counter = 0 let counter = 0
const timer: NodeJS.Timer = setInterval(() => { const timer: NodeJS.Timer = setInterval(() => {
get(`http://localhost:${port}`, res => { get(url, res => {
clearInterval(timer) clearInterval(timer)
console.log('[waitOn]', res.statusCode, res.statusMessage) console.log('[waitOn]', green(`"${url}" are already responsive.`), `(${res.statusCode}: ${res.statusMessage})`)
resolve(res.statusCode) resolve(res.statusCode)
}).on('error', err => { }).on('error', err => {
console.log('[waitOn]', `counter:${counter++}`) console.log('[waitOn]', `counter: ${counter++}`)
}) })
}, interval) }, interval)
}) })