-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
131 lines (124 loc) · 3.13 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
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
import externalGlobals from 'rollup-plugin-external-globals';
import localResolve from 'rollup-plugin-local-resolve';
import replace from '@rollup/plugin-replace';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import write from './plugins/rollup-plugin-write';
const { ROLLUP_WATCH } = process.env;
const external = [
/^lodash/,
/^@arkntools/,
'jimp',
/^@jimp\//,
'jszip',
/^simple-statistics/,
'./tools',
];
const localResolvePlugin = localResolve();
const lodashPlugin = optimizeLodashImports();
const babelOutputPlugin = getBabelOutputPlugin({
comments: false,
plugins: ['@babel/plugin-transform-modules-commonjs'],
});
const getConfig = name => ({
input: `dist/${name}.js`,
external,
plugins: [
localResolvePlugin,
lodashPlugin,
write({
targets: [
{
path: `dist/dist/${name}.d.ts`,
data: `export * from '../${name}';`,
},
],
}),
],
output: {
dir: 'dist/dist',
format: 'es',
plugins: [babelOutputPlugin],
},
});
const workerConfigPlugins = [
localResolvePlugin,
externalGlobals({
lodash: '_',
jimp: 'Jimp',
jszip: 'JSZip',
'simple-statistics': 'ss',
'@arkntools/scripts/dist/ocrad': 'OCRAD',
}),
];
const workerConfigs = [
{
input: 'dist/worker/index.js',
external,
plugins: [
localResolvePlugin,
lodashPlugin,
replace({
values: {
"from 'jimp';": "from '@arkntools/scripts/dist/jimp4worker';",
"import { linearRegressionLine, linearRegression } from 'simple-statistics';":
"import linearRegression from 'simple-statistics/src/linear_regression.js';\nimport linearRegressionLine from 'simple-statistics/src/linear_regression_line.js';",
},
delimiters: ['', ''],
preventAssignment: true,
}),
copy({
copyOnce: true,
targets: [
{
src: ['package.json', 'LICENSE', '*.md'],
dest: 'dist',
},
],
}),
],
output: {
file: ROLLUP_WATCH ? 'dist/worker.js' : 'dist/worker/index.js',
format: 'es',
},
},
];
if (!ROLLUP_WATCH) {
workerConfigs.push(
{
input: 'dist/worker/index.importScriptsJsDelivr.js',
external,
plugins: workerConfigPlugins,
output: {
file: 'dist/worker/index.importScriptsJsDelivr.js',
format: 'es',
},
},
{
input: 'dist/lib/index.js',
external,
plugins: workerConfigPlugins,
output: {
file: 'dist/worker/index.noImportScripts.js',
format: 'es',
},
},
);
workerConfigs[workerConfigs.length - 1].plugins.push(
write({
targets: [
{
path: 'dist/worker/index.d.ts',
data: "export * from '../lib';",
},
],
}),
del({
hook: 'writeBundle',
targets: ['dist/worker/importScripts.*', 'dist/worker/comlinkLoader.js'],
}),
);
}
export default [getConfig('index'), getConfig('tools'), ...workerConfigs];