-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
113 lines (111 loc) · 2.67 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
import alias from "@rollup/plugin-alias";
import cjs from "rollup-plugin-cjs-es";
import glob from "glob";
import externalGlobals from "rollup-plugin-external-globals";
import inline from "rollup-plugin-inline-js";
import re from "rollup-plugin-re";
import resolve from "@rollup/plugin-node-resolve";
import {terser} from "rollup-plugin-terser";
export default {
input: "src/index.js",
output: {
file: "dist/stylus-renderer.min.js",
format: "iife",
name: "StylusRenderer"
},
plugins: [
alias({
entries: {
events: require.resolve("./src/shim/events"),
url: require.resolve("./src/shim/url"),
crypto: require.resolve("./src/shim/crypto"),
glob: require.resolve("./src/shim/glob"),
fs: require.resolve("./src/shim/fs"),
path: require.resolve("path-browserify")
}
}),
shimEmpty([
"stylus/lib/visitor/sourcemapper.js",
"stylus/lib/functions/image-size.js",
...glob.sync("node_modules/debug/src/**.js").map(f => f.slice("node_modules/".length)),
]),
inline(),
resolve({
browser: true
}),
re({
patterns: [
{
match: /selector.js$/,
test: /\bnew require\b/g,
replace: "require"
},
{
match: /renderer.js$/,
test: /module\.exports = /g,
replace: "module.exports.Renderer = "
},
{
match: /arguments\.js$/,
test: /require\('\.\.\/nodes'\)/g,
replace: "{Expression: require('./expression')}"
},
{
match: /utils\.js$/,
test: /this\.indent/g,
replace: "this && this.indent"
},
{
match: /(utils|renderer)\.js$/,
test: /__dirname/,
replace: '"/"'
},
{
match: /\bs\.js$/,
test: /self\.options/g,
replace: "self && self.options"
}
]
}),
cjs({
nested: true
}),
re({
patterns: [
{
// https://github.com/rollup/rollup/issues/2322
test: /export default \(function/g,
replace: "export default (null, function"
}
]
}),
externalGlobals({
util: "nodeUtil"
}),
terser({
keep_fnames: true,
compress: {
passes: 3
}
})
]
};
function shimEmpty(files) {
files = files.map(f => require.resolve(f));
return {
name: "rollup-plugin-shim-empty",
transform(code, id) {
if (id[0] === "\x00") {
return;
}
if (files.includes(id)) {
return {
code: `
const noop = () => noop;
module.exports = noop;
`
};
}
}
};
}