forked from julianshapiro/velocity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
187 lines (177 loc) · 4.57 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* velocity-animate (C) 2014-2017 Julian Shapiro.
*
* Licensed under the MIT license. See LICENSE file in the project root for details.
*/
import fs from "fs";
import path from "path";
import process from "process";
import babel from "rollup-plugin-babel";
import license from "rollup-plugin-license";
import sourceMaps from "rollup-plugin-sourcemaps";
//import stripBanner from "rollup-plugin-strip-banner";
import tslint from "rollup-plugin-tslint";
import typescript from "rollup-plugin-typescript2";
import {terser} from "rollup-plugin-terser";
// Copy of https://github.com/mjeanroy/rollup-plugin-strip-banner without a fixed file extension check.
// Waiting for https://github.com/mjeanroy/rollup-plugin-strip-banner/pull/129
// MIT License Copyright (c) 2016 Mickael Jeanroy
import rollupPluginUtils from "rollup-pluginutils";
import extractBanner from "extract-banner";
import MagicString from "magic-string";
function stripBanner(options = {}) {
const filter = rollupPluginUtils.createFilter(options.include, options.exclude);
return {
transform(code, id) {
if (!filter(id)) {
return;
}
// Remove banner for JS files only
const ext = path.extname(id).toLowerCase(),
banner = extractBanner(code);
if (!banner || (ext !== '.js' && ext !== '.jsx' && ext !== '.ts' && ext !== '.tsx')) {
return;
}
// Use a magicString: it will generate the sourceMap at the end.
const magicString = new MagicString(code),
pos = code.indexOf(banner);
// Remove the banner with the magicString instance.
magicString.remove(pos, pos + banner.length);
// Trim left to remove blank spaces.
magicString.trimStart();
const result = {code: magicString.toString()};
if (options.sourceMap !== false) {
result.map = magicString.generateMap({hires: true});
}
return result;
}
};
}
// End of rollup-plugin-strip-banner
const pkg = require("./package.json"),
libraryName = "velocity",
tasks = [],
hasBuild = process.env.BUILD === "true",
hasMinify = process.env.MINIFY === "true",
hasTest = process.env.TEST === "true",
typescriptOptions = {
// verbosity: 2,
clean: true
},
terserOptions = {
output: {
comments: /velocity-animate \(C\)/
}
};
function getPlugins(tsconfig) {
return [
license({
banner: "velocity-animate (C) 2014-2017 Julian Shapiro.\n\n Licensed under the MIT license. See LICENSE file in the project root for details."
}),
stripBanner(),
typescript(Object.assign({}, typescriptOptions, {
tsconfig
})),
babel({
exclude: ["node_modules/**"]
})
];
}
if (hasBuild || hasMinify) {
fs.writeFileSync("version.ts", `/*\n * velocity-animate (C) 2014-2017 Julian Shapiro.\n *\n * Licensed under the MIT license. See LICENSE file in the project root for details.\n */\n\n// Automatically generated\nexport const VERSION = "${pkg.version}";\n`);
tasks.push({
input: "src/velocity.ts",
context: "window",
output: [{
file: pkg.main.replace(".min", ""),
name: "Velocity",
format: "umd",
sourcemap: true
}, {
file: pkg.module,
name: pkg.name,
format: "es",
sourcemap: true
}],
watch: {
include: "src/**"
},
plugins: [
tslint(),
...getPlugins("src/tsconfig.json"),
sourceMaps()
]
}, {
input: "src-ui/velocity.ui.ts",
external: ["velocity-animate"],
output: [{
file: pkg.main.replace(".min", ".ui"),
format: "umd",
sourcemap: true,
globals: {
"velocity-animate": "Velocity"
}
}],
watch: {
include: "src-ui/**"
},
plugins: [
tslint(),
...getPlugins("src-ui/tsconfig.json"),
sourceMaps()
]
});
if (hasMinify) {
tasks.push({
input: "src/velocity.ts",
context: "window",
output: [{
file: pkg.main,
name: "Velocity",
format: "umd",
sourcemap: false
}],
plugins: [
...getPlugins("src/tsconfig.json"),
terser(terserOptions)
]
}, {
input: "src-ui/velocity.ui.ts",
external: ["velocity-animate"],
output: [{
file: pkg.main.replace(".min", ".ui.min"),
format: "umd",
sourcemap: false,
globals: {
"velocity-animate": "Velocity"
}
}],
plugins: [
...getPlugins("src-ui/tsconfig.json"),
terser(terserOptions)
]
});
}
}
if (hasTest) {
tasks.push({
input: "test/src/test.ts",
external: ["qunit", "velocity-animate"],
context: "window",
output: [{
file: "test/test.js",
format: "umd",
sourcemap: true,
globals: {
"velocity-animate": "Velocity",
"qunit": "QUnit"
}
}],
plugins: [
tslint(),
...getPlugins("test/src/tsconfig.json", true),
sourceMaps()
]
});
}
export default tasks;