forked from Kitware/vtk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
182 lines (168 loc) · 4.93 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
import * as path from 'path';
import * as glob from 'glob';
import autoprefixer from 'autoprefixer';
import alias from '@rollup/plugin-alias';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import eslint from '@rollup/plugin-eslint';
import ignore from 'rollup-plugin-ignore';
import json from '@rollup/plugin-json';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import replace from 'rollup-plugin-re';
import { string } from 'rollup-plugin-string';
import svgo from 'rollup-plugin-svgo';
import webworkerLoader from 'rollup-plugin-web-worker-loader';
import { rewriteFilenames } from './Utilities/rollup/plugin-rewrite-filenames';
const IGNORE_LIST = [
/[/\\]example_?[/\\]/,
/[/\\]test/,
/^Sources[/\\](Testing|ThirdParty)/,
];
function ignoreFile(name, ignoreList = IGNORE_LIST) {
return ignoreList.some((toMatch) => {
if (toMatch instanceof RegExp) {
return toMatch.test(name);
}
if (toMatch instanceof String) {
return toMatch === name;
}
return false;
});
}
const entryPoints = [
path.join('Sources', 'macros.js'),
path.join('Sources', 'vtk.js'),
path.join('Sources', 'favicon.js'),
...glob.sync('Sources/**/*.js').filter((file) => !ignoreFile(file)),
];
const entries = {};
entryPoints.forEach((entry) => {
entries[entry.replace(/^Sources[/\\]/, '')] = entry;
});
export default {
input: entries,
output: {
dir: 'dist/esm/',
format: 'es',
hoistTransitiveImports: false,
entryFileNames(chunkInfo) {
const name = chunkInfo.name;
// rewrite vtk.js files from Sources/.../<NAME>/index.js to .../<NAME>.js
const sourcesMatch = /^(.*?)[/\\]([A-Z]\w+)[/\\]index\.js$/.exec(name);
if (sourcesMatch) {
return path.join(sourcesMatch[1], `${sourcesMatch[2]}.js`);
}
return name;
},
manualChunks(id) {
// strip out full path to project root
return id.replace(`${path.resolve(__dirname)}${path.sep}`, '');
},
chunkFileNames(chunkInfo) {
let name = chunkInfo.name;
if (name.includes('node_modules')) {
return name.replace('node_modules', 'vendor');
}
if (!name.endsWith('.js')) {
name += '.js';
}
// throw all subscript prefixed chunks into a virtual folder
if (name.startsWith('_')) {
return name.replace(/^_/, `_virtual${path.sep}`);
}
// rewrite Sources/ chunks
return name.replace(/^Sources[/\\]/, '');
},
},
external: [/@babel\/runtime/],
plugins: [
// should be before commonjs
replace({
patterns: [
{
// match against jszip/lib/load.js
// Workaround until https://github.com/Stuk/jszip/pull/731 is merged
include: path.resolve(
__dirname,
'node_modules',
'jszip',
'lib',
'load.js'
),
test: /'use strict';\nvar utils = require\('.\/utils'\);/m,
replace: "'use strict'",
},
{
// match against jszip/lib/compressedObject.js
// Workaround until https://github.com/Stuk/jszip/pull/731 is merged
include: path.resolve(
__dirname,
'node_modules',
'jszip',
'lib',
'compressedObject.js'
),
test: /Crc32Probe'\);\nvar DataLengthProbe = require\('.\/stream\/DataLengthProbe'\);/m,
replace: "Crc32Probe');\n",
},
],
}),
alias({
entries: [
{ find: 'vtk.js', replacement: path.resolve(__dirname) },
],
}),
// ignore crypto module
ignore(['crypto']),
// needs to be before nodeResolve
webworkerLoader({
targetPlatform: 'browser',
// needs to match the full import statement path
pattern: /^.+\.worker(?:\.js)?$/,
// inline: true,
// preserveSource: true,
// outputFolder: 'WebWorkers',
}),
nodeResolve({
// don't rely on node builtins for web
preferBuiltins: false,
browser: true,
}),
!process.env.NOLINT &&
eslint({
include: '**/*.js',
exclude: 'node_modules/**',
}),
// commonjs should be before babel
commonjs({
transformMixedEsModules: true,
}),
// should be after commonjs
nodePolyfills(),
babel({
include: 'Sources/**',
exclude: 'node_modules/**',
extensions: ['.js'],
babelHelpers: 'runtime',
}),
string({
include: '**/*.glsl',
}),
json(),
svgo(),
postcss({
modules: true,
plugins: [autoprefixer],
}),
// windows ntfs hates colons in filenames,
// and node-resolve and web-worker-loader are notorious for
// inserting them into virtual modules that are written out
// to the filesystem via preserveModules: true.
rewriteFilenames({
find: /:/g,
replace: '_',
}),
],
};