Skip to content

Commit ee740ba

Browse files
committed
chore(rollup, webpack): print license in vtk.js file
in prod build
1 parent b2ae5a0 commit ee740ba

File tree

3 files changed

+79
-38
lines changed

3 files changed

+79
-38
lines changed

rollup.config.js

+52-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import pkgJSON from './package.json';
2222
import { rewriteFilenames } from './Utilities/rollup/plugin-rewrite-filenames';
2323
import { generateDtsReferences } from './Utilities/rollup/plugin-generate-references';
2424

25+
const fs = require('fs');
26+
2527
const relatifyImports = require('./Utilities/build/rewrite-imports');
2628

2729
const IGNORE_LIST = [
@@ -44,7 +46,6 @@ function ignoreFile(name, ignoreList = IGNORE_LIST) {
4446

4547
const entryPoints = [
4648
path.join('Sources', 'macros.js'),
47-
path.join('Sources', 'vtk.js'),
4849
path.join('Sources', 'favicon.js'),
4950
...glob.sync('Sources/**/*.js').filter((file) => !ignoreFile(file)),
5051
];
@@ -59,7 +60,8 @@ const outputDir = path.resolve('dist', 'esm');
5960
const dependencies = Object.keys(pkgJSON.dependencies || []);
6061
const peerDependencies = Object.keys(pkgJSON.peerDependencies || []);
6162

62-
export default {
63+
export default [
64+
{
6365
input: entries,
6466
output: {
6567
dir: outputDir,
@@ -105,9 +107,6 @@ export default {
105107
...peerDependencies.map((name) => new RegExp(`^${name}`)),
106108
],
107109
plugins: [
108-
alias({
109-
entries: [{ find: 'vtk.js', replacement: path.resolve(__dirname) }],
110-
}),
111110
// ignore crypto module
112111
ignore(['crypto']),
113112
// needs to be before nodeResolve
@@ -249,4 +248,51 @@ export default {
249248
],
250249
}),
251250
],
252-
};
251+
},
252+
{
253+
input: path.resolve(path.join('Sources', 'vtk.js')),
254+
output: {
255+
dir: outputDir,
256+
format: 'es',
257+
hoistTransitiveImports: false,
258+
intro() {
259+
return `/* ${fs.readFileSync(
260+
path.resolve(__dirname, './LICENSE'),
261+
'utf8'
262+
)} */`;
263+
},
264+
manualChunks(id) {
265+
// strip out full path to project root
266+
return id.replace(`${path.resolve(__dirname)}${path.sep}`, '');
267+
},
268+
},
269+
external: [
270+
...dependencies.map((name) => new RegExp(`^${name}`)),
271+
...peerDependencies.map((name) => new RegExp(`^${name}`)),
272+
],
273+
plugins: [
274+
alias({
275+
entries: [{ find: 'vtk.js', replacement: path.resolve(__dirname) }],
276+
}),
277+
nodeResolve({
278+
// don't rely on node builtins for web
279+
preferBuiltins: false,
280+
browser: true,
281+
}),
282+
!process.env.NOLINT &&
283+
eslint({
284+
include: '**/*.js',
285+
}),
286+
// commonjs should be before babel
287+
commonjs({
288+
transformMixedEsModules: true,
289+
}),
290+
// should be after commonjs
291+
nodePolyfills(),
292+
babel({
293+
extensions: ['.js'],
294+
babelHelpers: 'runtime',
295+
}),
296+
],
297+
},
298+
];

webpack.common.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,18 @@ const baseConfig = {
120120
// transforms typescript defs to use absolute imports
121121
if (absoluteFrom.endsWith('.d.ts')) {
122122
return absolutifyImports(content.toString(), (relImport) => {
123-
const importPath = path.join(path.dirname(absoluteFrom), relImport);
124-
return path.join('vtk.js', path.relative(__dirname, importPath));
123+
const importPath = path.join(
124+
path.dirname(absoluteFrom),
125+
relImport
126+
);
127+
return path.join(
128+
'vtk.js',
129+
path.relative(__dirname, importPath)
130+
);
125131
});
126132
}
127133
return content;
128-
}
134+
},
129135
},
130136
{ from: 'Utilities/prepare.js', to: 'Utilities/prepare.js' },
131137
{ from: 'Utilities/XMLConverter', to: 'Utilities/XMLConverter' },
@@ -145,7 +151,7 @@ const baseConfig = {
145151
pkg.main = './vtk.js';
146152
delete pkg.module;
147153
return JSON.stringify(pkg, null, 2);
148-
}
154+
},
149155
},
150156
],
151157
}),
@@ -190,10 +196,11 @@ const liteConfig = merge(
190196
},
191197
resolve: {
192198
alias: {
193-
'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps.json': path.join(
194-
__dirname,
195-
'Sources/Rendering/Core/ColorTransferFunction/LiteColorMaps.json'
196-
),
199+
'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps.json':
200+
path.join(
201+
__dirname,
202+
'Sources/Rendering/Core/ColorTransferFunction/LiteColorMaps.json'
203+
),
197204
},
198205
fallback: { stream: require.resolve('stream-browserify') },
199206
},

webpack.prod.js

+12-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
// node modules
2+
const path = require('path');
23
const { merge } = require('webpack-merge');
3-
const moment = require('moment');
44
const webpack = require('webpack');
5-
const TerserPlugin = require("terser-webpack-plugin");
5+
const fs = require('fs');
6+
const TerserPlugin = require('terser-webpack-plugin');
67

78
// webpack plugins
8-
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
9-
.BundleAnalyzerPlugin;
9+
const BundleAnalyzerPlugin =
10+
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
1011

1112
// config files
1213
const common = require('./webpack.common.js');
1314
const settings = require('./webpack.settings.js');
1415

15-
// Configure file banner
16-
function configureBanner() {
17-
return {
18-
banner: [
19-
'/*!',
20-
` * @project ${settings.name}`,
21-
` * @build ${moment().format('llll')} ET`,
22-
` * @copyright Copyright (c) ${moment().format('YYYY')} ${
23-
settings.copyright
24-
}`,
25-
' *',
26-
' */',
27-
'',
28-
].join('\n'),
29-
raw: true,
30-
};
31-
}
32-
3316
// Configure Bundle Analyzer
3417
function configureBundleAnalyzer(name) {
3518
return {
@@ -51,6 +34,7 @@ function configureOptimization() {
5134
/Sources\//,
5235
/Utilities\//,
5336
],
37+
extractComments: false,
5438
}),
5539
],
5640
};
@@ -63,8 +47,10 @@ module.exports = [
6347
devtool: 'source-map',
6448
optimization: configureOptimization(),
6549
plugins: [
50+
new webpack.BannerPlugin(
51+
`/* ${fs.readFileSync(path.resolve(__dirname, './LICENSE'), 'utf8')} */`
52+
),
6653
new webpack.optimize.ModuleConcatenationPlugin(),
67-
new webpack.BannerPlugin(configureBanner()),
6854
new BundleAnalyzerPlugin(configureBundleAnalyzer('vtk')),
6955
],
7056
}),
@@ -73,8 +59,10 @@ module.exports = [
7359
devtool: 'source-map',
7460
optimization: configureOptimization(),
7561
plugins: [
62+
new webpack.BannerPlugin(
63+
`/* ${fs.readFileSync(path.resolve(__dirname, './LICENSE'), 'utf8')} */`
64+
),
7665
new webpack.optimize.ModuleConcatenationPlugin(),
77-
new webpack.BannerPlugin(configureBanner()),
7866
new BundleAnalyzerPlugin(configureBundleAnalyzer('vtk-lite')),
7967
],
8068
}),

0 commit comments

Comments
 (0)