-
Notifications
You must be signed in to change notification settings - Fork 83
/
rollup.config.mjs
118 lines (115 loc) · 3.39 KB
/
rollup.config.mjs
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
import {METADATA, SCRIPT_INFO} from './src/meta.js';
import babel from '@rollup/plugin-babel';
import banner2 from 'rollup-plugin-banner2';
import commonjs from '@rollup/plugin-commonjs';
import dev from 'rollup-plugin-dev';
import ejs from 'rollup-plugin-ejs';
import json from '@rollup/plugin-json';
import replace from 'rollup-plugin-re';
import resolve from '@rollup/plugin-node-resolve';
import scss from 'rollup-plugin-scss-string';
// import {terser} from "rollup-plugin-terser";
// TODO commonjs bug https://github.com/rollup/plugins/issues/304
const basicConfig = {
context: 'window',
input: {
[SCRIPT_INFO.name]: './src/index.js'
},
output: {
dir: './dist',
entryFileNames: '[name].user.js',
format: 'iife',
strict: false // fix https://github.com/facebook/regenerator/blob/a755f3f0cd7928c1b89c251e5e84472aa31b7e33/packages/regenerator-runtime/runtime.js#L725
// globals: {
// "@babel/runtime/regenerator": "regeneratorRuntime"
// }
// https://github.com/rollup/rollup-plugin-babel/issues/306
},
plugins: [
replace({
verbose: false,
defines: {
IS_SKIP: false,
IS_REMOVE: true
},
patterns: [
{
include: 'src/**/*.js',
test: /(logger\.(?:trace|debug|info|warn|error))\((.*)\)/g,
replace: (_, p1, p2) => `${p1}("[Super-preloader]", ${p2.trim()})`
// All string in loggermust be wrapped in double quote
// const inBracket = [false, false];
// const splitLoc = [];
// for (let i = 0; i < p2.length; i++) {
// if (p2[i] === '"' && (i == 0 || p2[i - 1] !== "\\")) {
// inBracket[0] = !inBracket[0];
// } else if (p2[i] === "`") {
// inBracket[1] = !inBracket[1];
// }
// if (p2[i] === "," && !inBracket[0] && !inBracket[1]) {
// splitLoc.push(i);
// }
// }
// const args = [];
// for (let i = 0; i < splitLoc.length; i++) {
// const iBegin = i == 0 ? 0 : splitLoc[i - 1] + 1;
// args.push(p2.slice(iBegin, splitLoc[i]));
// }
// if (splitLoc.length === 0) {
// args.push(p2);
// } else {
// args.push(p2.slice(splitLoc[splitLoc.length - 1] + 1));
// }
// return `${p1}("[Super-preloader]", ${args.join(",")})`;
}
]
}),
banner2(() => METADATA),
ejs({
include: ['**/*.ejs'], // optional, '**/*.ejs' by default
compilerOptions: {
client: true,
strict: true // all variables in ejs should be "locals.XX"
}
}),
json({
compact: true
}),
scss({
include: ['**/*.scss', '**/*.sass', '**/*.css']
}),
babel({
babelHelpers: 'runtime',
exclude: 'node_modules/**'
}),
resolve({
browser: true
}),
commonjs({
ignoreGlobal: true, // to make text-encoding works
namedExport: {
loglevel: ['noConflict']
}
})
// terser({
// keep_fnames: true,
// keep_classnames: true,
// output: {
// beautify: true,
// preamble: METADATA
// }
// })
]
};
export default (commandLineArgs) => {
if (commandLineArgs.dev === true) {
basicConfig.plugins.push(
dev({
dirs: ['dist'],
host: 'localhost',
port: 8081
})
);
}
return basicConfig;
};