-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
91 lines (88 loc) · 2.83 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 告诉 rollup 他要打包什么
import clear from 'rollup-plugin-clear'
import screeps from 'rollup-plugin-screeps'
import copy from 'rollup-plugin-copy'
import typescript from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
let config
// 根据指定的目标获取对应的配置项
if (!process.env.DEST) console.log("未指定目标, 代码将被编译但不会上传")
else if (!(config = require("./.secret.json")[process.env.DEST])) {
throw new Error("无效目标,请检查 secret.json 中是否包含对应配置")
}
// 根据指定的配置决定是上传还是复制到文件夹
const pluginDeploy = config && config.copyPath ?
// 复制到指定路径
copy({
targets: [
{
src: 'dist/main.js',
dest: config.copyPath
},
{
src: 'src/module/layoutVisual/dynamic/algo_wasm_priorityqueue.wasm',
dest: config.copyPath
},
{
src: 'src/module/layoutVisual/dynamic/autoPlanner63.js',
dest: config.copyPath
},
// {
// src: 'src/module/layoutVisual/dynamic/autoPlannerdu.js',
// dest: config.copyPath
// },
{
src: 'dist/main.js.map',
dest: config.copyPath,
rename: name => name + '.map.js',
transform: contents => `module.exports = ${contents.toString()};`
}
],
hook: 'writeBundle',
verbose: true
}) :
// 更新 .map 到 .map.js 并上传
screeps({
config, dryRun: !config
})
export default {
// 源代码的入口是哪个文件
input: 'src/main.ts',
// 构建产物配置
output: {
// 输出到哪个文件
file: 'dist/main.js',
format: 'cjs',
sourcemap: true
},
plugins: [
// 清除上次编译成果
clear({ targets: ["dist"] }),
// 打包依赖
resolve(),
// 模块化依赖
commonjs(),
// 编译 ts
typescript({ tsconfig: "./tsconfig.json" }),
copy({
targets: [
{
src: 'src/module/layoutVisual/dynamic/algo_wasm_priorityqueue.wasm',
dest: 'dist'
},
{
src: 'src/module/layoutVisual/dynamic/autoPlanner63.js',
dest: 'dist'
},
// {
// src: 'src/module/layoutVisual/dynamic/autoPlannerdu.js',
// dest: 'dist'
// }
]
}),
// 执行上传或者复制
pluginDeploy
],
external: ['src/modules/layoutVisual/algo_wasm_priorityqueue.wasm'],
};