-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
57 lines (54 loc) · 1.68 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
import fs from "fs";
import typescript from "@rollup/plugin-typescript";
import serve from "rollup-plugin-serve";
import sourcemaps from "rollup-plugin-sourcemaps";
import postcss from "rollup-plugin-postcss";
import autoprefixer from "autoprefixer";
import postcssNormalize from "postcss-normalize";
import postcssImport from "postcss-import";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import external from "rollup-plugin-peer-deps-external";
import replace from "@rollup/plugin-replace";
import livereload from "rollup-plugin-livereload";
const envPlugins =
process.env.NODE_ENV === "development"
? [serve({ contentBase: "dist", port: 9999 }), livereload()]
: [];
function buildHTML() {
return {
name: "build-html",
buildStart: async function buildStart() {
const content = await fs.promises.readFile("./html/index.html", "utf-8");
return await fs.promises.writeFile("./dist/index.html", content);
},
};
}
export default [
{
input: "src/main.tsx",
output: {
file: "dist/bundle.js",
format: "cjs",
sourcemap: true,
},
plugins: [
replace({
"process.env.NODE_ENV": JSON.stringify("development"),
preventAssignment: true,
}),
external(),
resolve(),
commonjs(),
postcss({
inject: false, // don't inject JavaScript
extract: true, // write a CSS file
plugins: [postcssNormalize(), postcssImport(), autoprefixer()],
writeDefinitions: false, // true -> generate .css.d.ts files
}),
typescript({ tsconfig: "./tsconfig.json" }),
sourcemaps(),
buildHTML(),
].concat(envPlugins),
},
];