Skip to content

Commit

Permalink
fix: rollup-plugin-esbuild 低版本报错
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Feb 18, 2021
1 parent cbafc2c commit 48d5a92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 6 additions & 15 deletions script/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -26,14 +27,15 @@ 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',
// Like @rollup/plugin-replace
define: {
__VERSION__: '"x.y.z"'
},
tsconfig: 'tsconfig.json', // default
// Add extra loaders
loaders: {
// Add .json files support
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions script/utils.ts
Original file line number Diff line number Diff line change
@@ -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)
})
Expand Down

0 comments on commit 48d5a92

Please sign in to comment.