-
Notifications
You must be signed in to change notification settings - Fork 24
/
rollup.config.js
143 lines (132 loc) · 3.16 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { camelCase } from "lodash";
import path 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 license from "rollup-plugin-license";
import resolve from "rollup-plugin-node-resolve";
import replace from "rollup-plugin-replace";
import uglify from "rollup-plugin-uglify";
import vue from "rollup-plugin-vue";
import { minify } from "uglify-es";
import pack from "./package.json";
const projectName = "vfg-field-array";
// compute globals from dependencies
const globals =
pack.dependencies &&
Object.assign(
{},
...Object.keys(pack.dependencies).map(key => ({
[key]: camelCase(key)
}))
);
const builds = {
// (CommonJS). Used by bundlers e.g. Webpack & Browserify
cjs: {
entry: "src/index.js",
ignore: [
'vue',
'vue-form-generator',
'lodash.foreach'
],
dest: `dist/${projectName}.common.js`,
format: "cjs"
},
// (ES Modules). Used by bundlers that support ES Modules,
// e.g. Rollup & Webpack 2
esm: {
entry: "src/index.js",
ignore: [
'vue',
'vue-form-generator',
'lodash.foreach'
],
dest: `dist/${projectName}.esm.js`,
format: "es"
},
// build (Browser)
"umd-dev": {
entry: "src/index.umd.js",
dest: `dist/${projectName}.js`,
ignore: [
'vue',
'vue-form-generator',
'lodash.foreach'
],
format: "umd",
env: "development"
},
// production build (Browser)
"umd-prod": {
entry: "src/index.umd.js",
dest: `dist/${projectName}.min.js`,
ignore: [
'vue',
'vue-form-generator',
'lodash.foreach'
],
format: "umd",
env: "production"
}
};
function genConfig(name) {
const opts = builds[name];
const config = {
input: opts.entry,
external: ['vue', 'vue-form-generator', 'lodash.foreach'],
globals: { vue: 'Vue' },
plugins: [
resolve({
browser: true,
jsnext: true,
preferBuiltins: false,
extensions: [".js", ".json", ".vue"]
}),
commonjs(),
vue({ compileTemplate: true, css: true }),
json(),
babel({
exclude: "node_modules/**",
runtimeHelpers: true
}),
filesize()
].concat(opts.plugins || []),
output: {
exports: "named",
file: opts.dest,
format: opts.format,
// define globals in window from external dependencies
globals,
name: opts.moduleName || projectName
}
};
if (opts.env) {
config.plugins.push(
replace({
"process.env.NODE_ENV": JSON.stringify(opts.env)
})
);
// minify on production targets
if (opts.env === "production") {
config.plugins.push(uglify({}, minify));
}
}
// output a license to builds
config.plugins.push(
license({
sourceMap: true,
banner: {
file: path.resolve("LICENSE.md")
}
})
);
Object.defineProperty(config, "_name", {
enumerable: false,
value: name
});
return config;
}
const target = process.env.TARGET || "umd-prod";
console.log(genConfig(target));
module.exports = genConfig(target);