-
Notifications
You must be signed in to change notification settings - Fork 23
/
rollup.markdown-parser.js
100 lines (91 loc) · 2.31 KB
/
rollup.markdown-parser.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import json from "@rollup/plugin-json";
import { terser } from "rollup-plugin-terser";
import bundleSize from "rollup-plugin-bundle-size";
import copy from "rollup-plugin-copy";
import hash from "rollup-plugin-hash";
import postcss from "rollup-plugin-postcss";
import postcssImport from "postcss-import";
import del from "rollup-plugin-delete";
const fs = require("fs");
const mkdirp = require("mkdirp");
const writeIndexHtmlToBuild = bundleName => {
let indexHtml = fs.readFileSync(
"examples/markdown-parser/index.html",
"utf8"
);
mkdirp.sync("dist/examples/markdown-parser");
indexHtml = indexHtml.replace(
"<%BUNDLE%>",
bundleName.replace("dist/examples/markdown-parser/", "")
);
fs.writeFileSync(
"dist/examples/markdown-parser/index.html",
indexHtml,
"utf8"
);
};
const sourcemapOption = process.env.PROD ? undefined : "inline";
const babelPluginConfig = {
babelHelpers: "bundled",
presets: ["@babel/preset-env"],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-export-default-from",
["@babel/plugin-transform-react-jsx", { pragma: "h" }]
]
};
let plugins = [
postcss({
extensions: [".css"],
plugins: [postcssImport()]
}),
resolve(),
babel(babelPluginConfig),
commonjs(),
json(),
copy({
targets: []
})
];
if (process.env.DEV) {
writeIndexHtmlToBuild("index.iife.js");
}
if (process.env.PROD) {
plugins = [
...plugins,
terser({
mangle: true,
compress: true
}),
bundleSize(),
del({
targets: ["dist/examples/markdown-parser/bundle.*.js"]
}),
hash({
dest: "dist/examples/markdown-parser/bundle.[hash].js",
callback: bundleName => {
writeIndexHtmlToBuild(bundleName);
}
})
];
}
const mdBundles = [
{
input: "examples/markdown-parser/index.js",
output: {
file: "dist/examples/markdown-parser/index.iife.js",
format: "iife",
sourcemap: sourcemapOption,
banner: fs.readFileSync(
"examples/markdown-parser/assembly/as-mocks-banner.js",
"utf8"
)
},
plugins: plugins
}
];
export default mdBundles;