Skip to content

Commit

Permalink
chore(rollup, webpack): print license in vtk.js file
Browse files Browse the repository at this point in the history
in prod build
  • Loading branch information
joannacirillo committed Jun 23, 2022
1 parent 671c450 commit 7b3df29
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 34 deletions.
49 changes: 47 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import pkgJSON from './package.json';
import { rewriteFilenames } from './Utilities/rollup/plugin-rewrite-filenames';
import { generateDtsReferences } from './Utilities/rollup/plugin-generate-references';

const fs = require('fs');

const relatifyImports = require('./Utilities/build/rewrite-imports');

const IGNORE_LIST = [
Expand Down Expand Up @@ -59,7 +61,8 @@ const outputDir = path.resolve('dist', 'esm');
const dependencies = Object.keys(pkgJSON.dependencies || []);
const peerDependencies = Object.keys(pkgJSON.peerDependencies || []);

export default {
export default [
{
input: entries,
output: {
dir: outputDir,
Expand Down Expand Up @@ -249,4 +252,46 @@ export default {
],
}),
],
};
},{
input: path.resolve(path.join('Sources', 'vtk.js')),
output: {
file: path.join(outputDir, 'vtk.js'),
format: 'es',
hoistTransitiveImports: false,
intro() {
return `/* ${fs.readFileSync(
path.resolve(__dirname, './LICENSE'),
'utf8'
)} */`;
},
},
external: [
...dependencies.map((name) => new RegExp(`^${name}`)),
...peerDependencies.map((name) => new RegExp(`^${name}`)),
],
plugins: [
alias({
entries: [{ find: 'vtk.js', replacement: path.resolve(__dirname) }],
}),
nodeResolve({
// don't rely on node builtins for web
preferBuiltins: false,
browser: true,
}),
!process.env.NOLINT &&
eslint({
include: '**/*.js',
}),
// commonjs should be before babel
commonjs({
transformMixedEsModules: true,
}),
// should be after commonjs
nodePolyfills(),
babel({
extensions: ['.js'],
babelHelpers: 'runtime',
}),
],
},
];
23 changes: 15 additions & 8 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ const baseConfig = {
// transforms typescript defs to use absolute imports
if (absoluteFrom.endsWith('.d.ts')) {
return absolutifyImports(content.toString(), (relImport) => {
const importPath = path.join(path.dirname(absoluteFrom), relImport);
return path.join('vtk.js', path.relative(__dirname, importPath));
const importPath = path.join(
path.dirname(absoluteFrom),
relImport
);
return path.join(
'vtk.js',
path.relative(__dirname, importPath)
);
});
}
return content;
}
},
},
{ from: 'Utilities/prepare.js', to: 'Utilities/prepare.js' },
{ from: 'Utilities/XMLConverter', to: 'Utilities/XMLConverter' },
Expand All @@ -145,7 +151,7 @@ const baseConfig = {
pkg.main = './vtk.js';
delete pkg.module;
return JSON.stringify(pkg, null, 2);
}
},
},
],
}),
Expand Down Expand Up @@ -190,10 +196,11 @@ const liteConfig = merge(
},
resolve: {
alias: {
'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps.json': path.join(
__dirname,
'Sources/Rendering/Core/ColorTransferFunction/LiteColorMaps.json'
),
'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps.json':
path.join(
__dirname,
'Sources/Rendering/Core/ColorTransferFunction/LiteColorMaps.json'
),
},
fallback: { stream: require.resolve('stream-browserify') },
},
Expand Down
36 changes: 12 additions & 24 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
// node modules
const path = require('path');
const { merge } = require('webpack-merge');
const moment = require('moment');
const webpack = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const fs = require('fs');
const TerserPlugin = require('terser-webpack-plugin');

// webpack plugins
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

// config files
const common = require('./webpack.common.js');
const settings = require('./webpack.settings.js');

// Configure file banner
function configureBanner() {
return {
banner: [
'/*!',
` * @project ${settings.name}`,
` * @build ${moment().format('llll')} ET`,
` * @copyright Copyright (c) ${moment().format('YYYY')} ${
settings.copyright
}`,
' *',
' */',
'',
].join('\n'),
raw: true,
};
}

// Configure Bundle Analyzer
function configureBundleAnalyzer(name) {
return {
Expand All @@ -51,6 +34,7 @@ function configureOptimization() {
/Sources\//,
/Utilities\//,
],
extractComments: false,
}),
],
};
Expand All @@ -63,8 +47,10 @@ module.exports = [
devtool: 'source-map',
optimization: configureOptimization(),
plugins: [
new webpack.BannerPlugin(
`/* ${fs.readFileSync(path.resolve(__dirname, './LICENSE'), 'utf8')} */`
),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.BannerPlugin(configureBanner()),
new BundleAnalyzerPlugin(configureBundleAnalyzer('vtk')),
],
}),
Expand All @@ -73,8 +59,10 @@ module.exports = [
devtool: 'source-map',
optimization: configureOptimization(),
plugins: [
new webpack.BannerPlugin(
`/* ${fs.readFileSync(path.resolve(__dirname, './LICENSE'), 'utf8')} */`
),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.BannerPlugin(configureBanner()),
new BundleAnalyzerPlugin(configureBundleAnalyzer('vtk-lite')),
],
}),
Expand Down

0 comments on commit 7b3df29

Please sign in to comment.