加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 3.74 KB
一键复制 编辑 原始数据 按行查看 历史
import { spawn } from 'child_process';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import builtinModules from 'builtin-modules';
import electron from 'electron';
import copy from 'rollup-plugin-copy';
import appManifest from './package.json';
const NODE_ENV = process.env.NODE_ENV || 'development';
const canRun = process.env.ROLLUP_WATCH === 'true' && process.env.NO_RUN !== 'true';
const run = () => {
if (!canRun) {
return;
}
let proc = null;
return {
writeBundle: async () => {
if (proc) {
proc.kill();
await new Promise((resolve) => proc.on('close', resolve));
}
console.log(proc ? 'Restarting main process...' : 'Starting main process...');
proc = spawn(electron, ['.'], { stdio: 'inherit' });
proc.on('close', () => {
proc = null;
});
},
};
};
export default [
{
external: [
...builtinModules,
...Object.keys(appManifest.dependencies),
...Object.keys(appManifest.devDependencies),
].filter((moduleName) => moduleName !== '@bugsnag/js'),
input: 'src/rootWindow.ts',
preserveEntrySignatures: 'strict',
plugins: [
json(),
replace({
'process.env.BUGSNAG_API_KEY': JSON.stringify(process.env.BUGSNAG_API_KEY),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
typescript({
noEmitOnError: false,
}),
babel({
babelHelpers: 'bundled',
}),
nodeResolve({
browser: true,
}),
commonjs(),
],
output: {
dir: 'app',
format: 'cjs',
sourcemap: true,
},
},
{
external: [
...builtinModules,
...Object.keys(appManifest.dependencies),
...Object.keys(appManifest.devDependencies),
].filter((moduleName) => moduleName !== '@bugsnag/js'),
input: 'src/preload.ts',
plugins: [
json(),
replace({
'process.env.BUGSNAG_API_KEY': JSON.stringify(process.env.BUGSNAG_API_KEY),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
typescript({ noEmitOnError: false }),
babel({
babelHelpers: 'bundled',
}),
nodeResolve({
browser: true,
}),
commonjs(),
],
output: [
{
dir: 'app',
format: 'cjs',
sourcemap: 'inline',
},
],
},
{
input: 'src/injected.ts',
plugins: [
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
typescript({ noEmitOnError: false }),
babel({
babelHelpers: 'bundled',
}),
nodeResolve({
browser: true,
}),
commonjs(),
],
output: [
{
dir: 'app',
format: 'iife',
sourcemap: 'inline',
},
],
},
{
external: [
...builtinModules,
...Object.keys(appManifest.dependencies),
...Object.keys(appManifest.devDependencies),
],
input: 'src/main.ts',
plugins: [
copy({
targets: [
{ src: 'src/public/*', dest: 'app' },
{ src: 'node_modules/@rocket.chat/icons/dist/*', dest: 'app/icons' },
],
}),
json(),
replace({
'process.env.BUGSNAG_API_KEY': JSON.stringify(process.env.BUGSNAG_API_KEY),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
typescript({ noEmitOnError: false }),
babel({
babelHelpers: 'bundled',
}),
nodeResolve(),
commonjs(),
run(),
],
output: {
dir: 'app',
format: 'cjs',
sourcemap: 'inline',
},
},
];
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化