screepCode/rollup.config.mjs

58 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-11-03 20:56:43 +08:00
import clear from 'rollup-plugin-clear'
import screeps from 'rollup-plugin-screeps'
import copy from 'rollup-plugin-copy'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2' // <== 新增这一行
import { config } from './.secret.js'
2024-11-03 20:56:43 +08:00
console.log(config[process.env.DEST])
2024-11-03 20:56:43 +08:00
// 根据指定的目标获取对应的配置项
if (!process.env.DEST) console.log("未指定目标, 代码将被编译但不会上传")
else if (config.main == null && config.local == null) {
2024-11-03 20:56:43 +08:00
throw new Error("无效目标,请检查 secret.json 中是否包含对应配置")
}
let runConfig = config[process.env.DEST]
2024-11-03 20:56:43 +08:00
// 根据指定的配置决定是上传还是复制到文件夹
const pluginDeploy = runConfig && runConfig.copyPath ?
2024-11-03 20:56:43 +08:00
// 复制到指定路径
copy({
targets: [
{
src: 'dist/main.js',
dest: runConfig.copyPath
2024-11-03 20:56:43 +08:00
},
{
src: 'dist/main.js.map',
dest: runConfig.copyPath,
2024-11-03 20:56:43 +08:00
rename: name => name + '.map.js',
transform: contents => `module.exports = ${contents.toString()};`
}
],
hook: 'writeBundle',
verbose: true
}) :
// 更新 .map 到 .map.js 并上传
screeps({ runConfig, dryRun: !config })
2024-11-03 20:56:43 +08:00
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"}),
// 执行上传或者复制
pluginDeploy
]
};