Skip to content

Commit 7b3df29

Browse files
committed
chore(rollup, webpack): print license in vtk.js file
in prod build
1 parent 671c450 commit 7b3df29

File tree

3 files changed

+74
-34
lines changed

3 files changed

+74
-34
lines changed

rollup.config.js

Lines changed: 47 additions & 2 deletions
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 = [
@@ -59,7 +61,8 @@ const outputDir = path.resolve('dist', 'esm');
5961
const dependencies = Object.keys(pkgJSON.dependencies || []);
6062
const peerDependencies = Object.keys(pkgJSON.peerDependencies || []);
6163

62-
export default {
64+
export default [
65+
{
6366
input: entries,
6467
output: {
6568
dir: outputDir,
@@ -249,4 +252,46 @@ export default {
249252
],
250253
}),
251254
],
252-
};
255+
},{
256+
input: path.resolve(path.join('Sources', 'vtk.js')),
257+
output: {
258+
file: path.join(outputDir, 'vtk.js'),
259+
format: 'es',
260+
hoistTransitiveImports: false,
261+
intro() {
262+
return `/* ${fs.readFileSync(
263+
path.resolve(__dirname, './LICENSE'),
264+
'utf8'
265+
)} */`;
266+
},
267+
},
268+
external: [
269+
...dependencies.map((name) => new RegExp(`^${name}`)),
270+
...peerDependencies.map((name) => new RegExp(`^${name}`)),
271+
],
272+
plugins: [
273+
alias({
274+
entries: [{ find: 'vtk.js', replacement: path.resolve(__dirname) }],
275+
}),
276+
nodeResolve({
277+
// don't rely on node builtins for web
278+
preferBuiltins: false,
279+
browser: true,
280+
}),
281+
!process.env.NOLINT &&
282+
eslint({
283+
include: '**/*.js',
284+
}),
285+
// commonjs should be before babel
286+
commonjs({
287+
transformMixedEsModules: true,
288+
}),
289+
// should be after commonjs
290+
nodePolyfills(),
291+
babel({
292+
extensions: ['.js'],
293+
babelHelpers: 'runtime',
294+
}),
295+
],
296+
},
297+
];

webpack.common.js

Lines changed: 15 additions & 8 deletions
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

Lines changed: 12 additions & 24 deletions
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)