-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
134 lines (121 loc) · 3.09 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
"use strict";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { babel } from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
const replace = require("@rollup/plugin-replace");
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
const html = require("@rollup/plugin-html");
const htmlTemplate = require("./build/html.js");
const banner = require("./build/banner.js");
export default (commandLineArgs) => {
const DEMO = commandLineArgs.configDemo === true;
// this will make Rollup ignore the CLI argument
delete commandLineArgs.configDemo;
const libraryName = "AlpineSteps";
const BUNDLE = process.env.BUNDLE === "true";
const ESM = process.env.ESM === "true";
let outputFile = `steps${ESM ? ".esm" : ""}`;
const external = [];
const globals = [];
const plugins = [
commonjs(),
babel({
// Only transpile our source code
exclude: "node_modules/**",
// Include the helpers in the bundle, at most one copy of each
babelHelpers: "bundled",
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
},
],
],
}),
];
if (BUNDLE) {
outputFile += DEMO ? "" : ".bundle";
plugins.push(
replace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
nodeResolve()
);
}
if (DEMO) {
plugins.push(
html({
template: htmlTemplate({
vendors: [
{
type: "js",
pos: "before",
attributes: {
src: "https://unpkg.com/[email protected]/dist/cdn.min.js",
defer: true,
},
},
{
type: "css",
pos: "before",
attributes: {
href: "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
integrity:
"sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT",
crossorigin: "anonymous",
},
},
],
}),
title: "Alpine Steps Demo",
}),
serve({
open: true,
contentBase: "demo",
}),
livereload({
watch: "demo",
})
);
}
const rollupConfig = {
input: "src/index.js",
output: [
{
banner,
file: DEMO ? `demo/${outputFile}.js` : `dist/${outputFile}.js`,
format: ESM ? "es" : "umd",
globals,
sourcemap: true,
},
],
external,
plugins,
};
if (!DEMO) {
rollupConfig.output.push({
banner,
file: `dist/${outputFile}.min.js`,
format: ESM ? "es" : "umd",
globals,
plugins: [terser()],
sourcemap: true,
});
}
if (!ESM) {
for (
let i = 0, outputs = rollupConfig.output, output;
(output = outputs[i]);
i++
) {
output.name = libraryName;
}
}
return rollupConfig;
};