2020-12-24 10:17:27 +08:00
|
|
|
import { join } from 'path'
|
|
|
|
import { RollupOptions } from 'rollup'
|
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
|
|
import commonjs from '@rollup/plugin-commonjs'
|
|
|
|
import esbuild from 'rollup-plugin-esbuild'
|
|
|
|
import alias from '@rollup/plugin-alias'
|
|
|
|
import json from '@rollup/plugin-json'
|
2021-02-18 14:45:20 +08:00
|
|
|
import externals from 'rollup-plugin-node-externals'
|
2020-08-16 20:42:52 +08:00
|
|
|
|
2020-12-24 10:17:27 +08:00
|
|
|
export default (env = 'production') => {
|
|
|
|
const options: RollupOptions = {
|
|
|
|
input: join(__dirname, '../src/main/index.ts'),
|
2020-08-16 20:42:52 +08:00
|
|
|
output: {
|
2020-12-24 10:17:27 +08:00
|
|
|
file: join(__dirname, '../dist/main/_.js'),
|
2020-08-16 20:42:52 +08:00
|
|
|
format: 'cjs',
|
|
|
|
name: 'ElectronMainBundle',
|
|
|
|
sourcemap: true,
|
|
|
|
},
|
|
|
|
plugins: [
|
2020-12-24 10:17:27 +08:00
|
|
|
nodeResolve({ preferBuiltins: true, browser: true }), // 消除碰到 node.js 模块时⚠警告
|
2020-08-16 20:42:52 +08:00
|
|
|
commonjs(),
|
2020-09-06 17:35:02 +08:00
|
|
|
json(),
|
2020-08-26 18:24:01 +08:00
|
|
|
esbuild({
|
|
|
|
// All options are optional
|
|
|
|
include: /\.[jt]sx?$/, // default, inferred from `loaders` option
|
|
|
|
exclude: /node_modules/, // default
|
|
|
|
// watch: process.argv.includes('--watch'), // rollup 中有配置
|
|
|
|
sourceMap: false, // default
|
2021-02-18 14:45:20 +08:00
|
|
|
minify: env === 'production',
|
2020-08-26 18:24:01 +08:00
|
|
|
target: 'es2017', // default, or 'es20XX', 'esnext'
|
|
|
|
jsxFactory: 'React.createElement',
|
|
|
|
jsxFragment: 'React.Fragment',
|
|
|
|
// Like @rollup/plugin-replace
|
|
|
|
define: {
|
|
|
|
__VERSION__: '"x.y.z"'
|
|
|
|
},
|
2021-02-18 14:45:20 +08:00
|
|
|
tsconfig: 'tsconfig.json', // default
|
2020-08-26 18:24:01 +08:00
|
|
|
// Add extra loaders
|
|
|
|
loaders: {
|
|
|
|
// Add .json files support
|
|
|
|
// require @rollup/plugin-commonjs
|
|
|
|
'.json': 'json',
|
|
|
|
// Enable JSX in .js files too
|
|
|
|
'.js': 'jsx'
|
2020-09-06 17:35:02 +08:00
|
|
|
},
|
2020-08-26 18:24:01 +08:00
|
|
|
}),
|
2020-09-06 17:35:02 +08:00
|
|
|
alias({
|
|
|
|
entries: [
|
2020-12-24 10:17:27 +08:00
|
|
|
{ find: '@main', replacement: join(__dirname, '../src/main'), },
|
2020-09-06 17:35:02 +08:00
|
|
|
]
|
2020-12-24 18:36:41 +08:00
|
|
|
}),
|
2021-02-18 14:45:20 +08:00
|
|
|
externals(),
|
2020-08-16 20:42:52 +08:00
|
|
|
],
|
2021-02-18 14:45:20 +08:00
|
|
|
external: ['electron'],
|
2020-08-16 20:42:52 +08:00
|
|
|
}
|
2020-12-24 10:17:27 +08:00
|
|
|
|
|
|
|
return options
|
2020-08-26 18:24:01 +08:00
|
|
|
}
|