forked from sloria/jrnl-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
78 lines (72 loc) · 1.94 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
import { resolve } from "path";
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import json from "@rollup/plugin-json";
import nodeBuiltins from "rollup-plugin-node-builtins";
import nodeGlobals from "rollup-plugin-node-globals";
import nodeResolve from "@rollup/plugin-node-resolve";
import postcss from "rollup-plugin-postcss";
import replace from "@rollup/plugin-replace";
import serve from "rollup-plugin-serve";
import typescript from "@rollup/plugin-typescript";
import { terser } from "rollup-plugin-terser";
const env = process.env.NODE_ENV;
const standalone = process.env.STANDALONE === "true";
const config = {
plugins: [typescript(), postcss()],
watch: {
chokidar: true,
include: "src/**"
}
};
if (standalone) {
config.input = resolve("src", "standalone.tsx");
const outputSuffix = env === "production" ? ".min.js" : ".js";
config.output = {
file: `dist/jrnl-render.standalone${outputSuffix}`,
format: "iife"
};
config.plugins.push(
nodeResolve({ preferBuiltins: false }),
replace({
"process.env.NODE_ENV": JSON.stringify(env)
}),
commonjs()
);
if (env === "production") {
config.plugins.push(terser());
}
} else {
config.input = resolve("src", "index.tsx");
const outputSuffix = env === "production" ? ".debug.js" : ".js";
config.output = {
file: `dist/jrnl-render${outputSuffix}`,
format: "cjs"
};
config.external = [
"react",
"react-dom",
"jrnl-parse",
"slugify",
"remark",
"remark-ping",
"remark-rehype",
"rehype-stringify",
"rehype-highlight"
// "react-icons/io",
];
}
config.plugins.push(
babel({
exclude: ["**/*.json"]
}),
nodeBuiltins(),
nodeGlobals(),
json()
);
if (process.env.SERVE === "true") {
config.plugins.push(serve({ contentBase: ["dist", "example"], open: true }));
}
config.plugins.push(filesize());
export default config;