-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
62 lines (56 loc) · 1.57 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
import serve from "rollup-plugin-serve";
import terser from '@rollup/plugin-terser';
import fs from 'fs';
import copy from "rollup-plugin-copy";
// Import custom plugins
import pluginRenderEJS from "./plugins/plugin-render-ejs";
import pluginAddJS from "./plugins/plugin-add-js";
const IS_PRODUCTION = !process.env.ROLLUP_WATCH;
// Clear the build folder if it exists
if(fs.existsSync("build/")) {
fs.rmSync("build/", {
recursive: true
})
} else {
fs.mkdirSync("build/");
fs.mkdirSync("build/assets/");
}
// Copy static assets directly
fs.cpSync("src/assets/", "build/assets/", { recursive: true });
const EJS_GLOBAL_DATA = {
IS_PRODUCTION: IS_PRODUCTION,
IS_DEV: !IS_PRODUCTION,
};
export default {
input: "src/index.js",
output: {
dir: 'build',
format: 'cjs'
},
plugins: [
// Watch some root directory files
{
buildStart: function() {
["src/root/index.css"].forEach(filename => {
this.addWatchFile(filename);
});
}
},
copy({
targets: [{ src: "src/root/*", dest: "build/" }]
}),
// Add service worker
pluginAddJS(["src/service-worker.js"]),
// Generate index.html
pluginRenderEJS({ ...EJS_GLOBAL_DATA }, [
"src/index.ejs",
]),
// Minify JS in production
IS_PRODUCTION && terser({}),
// Locally serve content in development
!IS_PRODUCTION && serve({
port: 5500,
contentBase: 'build',
}),
]
};