|
| 1 | +const path = require('path'); |
| 2 | +const webpack = require('webpack'); |
| 3 | +const autoprefixer = require('autoprefixer'); |
| 4 | +// Plugins |
| 5 | +const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') |
| 6 | + .BundleAnalyzerPlugin; |
| 7 | +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); |
| 8 | +const vtkRules = require('vtk.js/Utilities/config/dependency.js').webpack.core |
| 9 | + .rules; |
| 10 | + |
| 11 | +const ENTRY_VTK_EXT = path.join(__dirname, './../src/index.js'); |
| 12 | +const SRC_PATH = path.join(__dirname, './../src'); |
| 13 | +const OUT_PATH = path.join(__dirname, './../dist'); |
| 14 | + |
| 15 | +/** |
| 16 | + * `argv` are options from the CLI. They will override our config here if set. |
| 17 | + * `-d` - Development shorthand, sets `debug`, `devtool`, and `mode` |
| 18 | + * `-p` - Production shorthand, sets `minimize`, `NODE_ENV`, and `mode` |
| 19 | + */ |
| 20 | +module.exports = (env, argv) => { |
| 21 | + const isProdBuild = argv.mode !== 'development'; |
| 22 | + const outputFilename = isProdBuild ? '[name].umd.min.js' : '[name].umd.js'; |
| 23 | + |
| 24 | + return { |
| 25 | + entry: { |
| 26 | + vtkViewport: ENTRY_VTK_EXT, |
| 27 | + }, |
| 28 | + devtool: 'source-map', |
| 29 | + output: { |
| 30 | + path: OUT_PATH, |
| 31 | + filename: outputFilename, |
| 32 | + library: 'VTKViewport', |
| 33 | + libraryTarget: 'umd', |
| 34 | + globalObject: 'this', |
| 35 | + }, |
| 36 | + module: { |
| 37 | + rules: [ |
| 38 | + { |
| 39 | + test: /\.(js|jsx)$/, |
| 40 | + exclude: /node_modules/, |
| 41 | + use: ['babel-loader'], |
| 42 | + }, |
| 43 | + { |
| 44 | + test: /\.css$/, |
| 45 | + exclude: /\.module\.css$/, |
| 46 | + use: [ |
| 47 | + 'style-loader', |
| 48 | + 'css-loader', |
| 49 | + { |
| 50 | + loader: 'postcss-loader', |
| 51 | + options: { |
| 52 | + plugins: () => [autoprefixer('last 2 version', 'ie >= 10')], |
| 53 | + }, |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + ].concat(vtkRules), |
| 58 | + }, |
| 59 | + resolve: { |
| 60 | + modules: [path.resolve(__dirname, './../node_modules'), SRC_PATH], |
| 61 | + }, |
| 62 | + externals: [ |
| 63 | + // Used to build/load metadata |
| 64 | + { |
| 65 | + 'cornerstone-core': { |
| 66 | + commonjs: 'cornerstone-core', |
| 67 | + commonjs2: 'cornerstone-core', |
| 68 | + amd: 'cornerstone-core', |
| 69 | + root: 'cornerstone', |
| 70 | + }, |
| 71 | + // Vector 3 use |
| 72 | + 'cornerstone-math': { |
| 73 | + commonjs: 'cornerstone-math', |
| 74 | + commonjs2: 'cornerstone-math', |
| 75 | + amd: 'cornerstone-math', |
| 76 | + root: 'cornerstoneMath', |
| 77 | + }, |
| 78 | + // |
| 79 | + react: 'react', |
| 80 | + // https://webpack.js.org/guides/author-libraries/#external-limitations |
| 81 | + 'vtk.js/Sources': { |
| 82 | + commonjs: 'vtk.js', |
| 83 | + commonjs2: 'vtk.js', |
| 84 | + amd: 'vtk.js', |
| 85 | + root: 'vtk.js', |
| 86 | + }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + node: { |
| 90 | + // https://github.com/webpack-contrib/style-loader/issues/200 |
| 91 | + Buffer: false, |
| 92 | + }, |
| 93 | + plugins: [ |
| 94 | + // Uncomment to generate bundle analyzer |
| 95 | + new BundleAnalyzerPlugin(), |
| 96 | + // Show build progress |
| 97 | + new webpack.ProgressPlugin(), |
| 98 | + // Clear dist between builds |
| 99 | + // new CleanWebpackPlugin(), |
| 100 | + ], |
| 101 | + }; |
| 102 | +}; |
0 commit comments