optimise onwrite hook of rollup plugin, clean up dist folder before bundling
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash": "^4.14.85",
|
"@types/lodash": "^4.14.85",
|
||||||
"rollup": "^0.51.8",
|
"rollup": "^0.51.8",
|
||||||
|
"rollup-plugin-clean": "^1.0.0",
|
||||||
"rollup-plugin-commonjs": "^8.2.6",
|
"rollup-plugin-commonjs": "^8.2.6",
|
||||||
"rollup-plugin-node-resolve": "^3.0.0",
|
"rollup-plugin-node-resolve": "^3.0.0",
|
||||||
"rollup-plugin-screeps-upload": "git+https://github.com/ezolenko/rollup-plugin-screeps-upload.git#master",
|
"rollup-plugin-screeps-upload": "git+https://github.com/ezolenko/rollup-plugin-screeps-upload.git#master",
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import clean from "rollup-plugin-clean";
|
||||||
import resolve from "rollup-plugin-node-resolve";
|
import resolve from "rollup-plugin-node-resolve";
|
||||||
import commonjs from "rollup-plugin-commonjs";
|
import commonjs from "rollup-plugin-commonjs";
|
||||||
import screepsUpload from "rollup-plugin-screeps-upload";
|
import screepsUpload from "rollup-plugin-screeps-upload";
|
||||||
import typescript from "rollup-plugin-typescript2";
|
import typescript from "rollup-plugin-typescript2";
|
||||||
|
|
||||||
const getSourcemapFilename = () => "main.js.map.js";
|
|
||||||
|
|
||||||
// In Screeps, require only works for exported content
|
// In Screeps, require only works for exported content
|
||||||
// This "plugin" prepends an export to source maps so that it can be loaded in screeps via require`
|
// This "plugin" prepends an export to source maps so that it can be loaded in screeps via require`
|
||||||
function exportSourceMaps(options) {
|
function exportSourceMaps(options) {
|
||||||
@@ -23,11 +22,12 @@ function exportSourceMaps(options) {
|
|||||||
return "module.exports = " + tmp.apply(this, arguments) + ";";
|
return "module.exports = " + tmp.apply(this, arguments) + ";";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onwrite: function ({ bundle }) {
|
onwrite: function () {
|
||||||
const map = bundle.map
|
// Rename generated source file
|
||||||
fs.writeFileSync(path.resolve(__dirname, `./dist/${options || getSourcemapFilename()}`), map);
|
fs.renameSync(
|
||||||
// Delete the old file
|
path.resolve(__dirname, "./dist", "main.js.map"),
|
||||||
fs.unlinkSync(path.resolve(__dirname, "./dist/main.js.map"));
|
path.resolve(__dirname, "./dist", options.filename || "main.js.map.js")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,10 +42,11 @@ export default {
|
|||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
|
clean(),
|
||||||
resolve(),
|
resolve(),
|
||||||
commonjs(),
|
commonjs(),
|
||||||
typescript({tsconfig: "./tsconfig.json"}),
|
typescript({tsconfig: "./tsconfig.json"}),
|
||||||
exportSourceMaps("main.js.map.js"),
|
exportSourceMaps({filename: "./main.js.map.js"}),
|
||||||
screepsUpload("./screeps.json")
|
screepsUpload("./screeps.json")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user