forked from kccd/nkc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
85 lines (80 loc) · 2.65 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
79
80
81
82
83
84
85
import path from "path";
import globby from "globby";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
import { babel } from "@rollup/plugin-babel";
import vue from "rollup-plugin-vue";
import json from "@rollup/plugin-json";
import styles from "rollup-plugin-styles";
import buble from "@rollup/plugin-buble";
import replace from "@rollup/plugin-replace";
const DIST_DIR = process.env.NODE_ENV === "production"? "dist-prod": "dist";
const LIB_DIR_PATTERN = "!pages/**/lib";
const SCRIPTS_PATTERNS = ["pages/**/*.js", LIB_DIR_PATTERN];
const STYLES_PATTERNS = ["pages/**/*.less", LIB_DIR_PATTERN];
function getOutputPath(filename, outputExt) {
const ext = path.extname(filename);
const basename = path.basename(filename, ext);
return path.join(__dirname, DIST_DIR, filename, "../", basename + (outputExt || ext));
}
export default (async () => {
const scriptFiles = await globby(SCRIPTS_PATTERNS);
const styleFiles = await globby(STYLES_PATTERNS);
let configs = [
// scripts
...scriptFiles.map(filename => {
return {
input: filename,
output: {
name: path.basename(filename, ".js"),
file: getOutputPath(filename),
format: "umd",
sourcemap: process.env.NODE_ENV === "production" ? false : "inline",
compact: false
},
plugins: [
nodeResolve(),
commonjs(),
json(),
styles(),
vue({ needMap: false }),
babel({
babelHelpers: "bundled",
extensions: [ ".js", ".ts", ".tsx", ".jsx", ".es6", ".es", ".mjs", ".vue" ]
}),
buble({ transforms: { forOf: false } }),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
process.env.NODE_ENV === "production" && terser()
],
cache: true
}
}),
// styles
...styleFiles.map(filename => {
const tempFile = getOutputPath(filename, ".css.js");
const basename = path.basename(filename, path.extname(filename));
return {
input: filename,
output: {
file: tempFile,
assetFileNames: "[name][extname]",
format: "umd",
name: basename,
exports: "named"
},
plugins: [
styles({
mode: ["extract", basename + ".css"],
minimize: process.env.NODE_ENV === "production",
sourceMap: process.env.NODE_ENV === "production" ? false : "inline"
})
]
}
})
];
return configs;
})();