From 2a36e7ce0febae1e04bec2bb8d92983dc32b71ba Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 24 Aug 2020 01:20:37 +0800 Subject: Migrate to webpack chain. --- Timeline/ClientApp/webpack.config.prod.js | 96 ++++++++----------------------- 1 file changed, 24 insertions(+), 72 deletions(-) (limited to 'Timeline/ClientApp/webpack.config.prod.js') diff --git a/Timeline/ClientApp/webpack.config.prod.js b/Timeline/ClientApp/webpack.config.prod.js index d0c72381..e3ef65e1 100644 --- a/Timeline/ClientApp/webpack.config.prod.js +++ b/Timeline/ClientApp/webpack.config.prod.js @@ -1,84 +1,36 @@ const path = require('path'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin'); const WorkboxPlugin = require('workbox-webpack-plugin'); -const PnpWebpackPlugin = require('pnp-webpack-plugin'); -const { commonRules, htmlCommonConfig } = require('./webpack.common'); +const config = require('./webpack.common'); -const config = { - entry: ['./src/app/index.tsx', './src/app/service-worker.tsx'], - mode: 'production', - devtool: 'source-map', - module: { - rules: [ - ...commonRules, - { - test: /\.ts(x?)$/, - exclude: /node_modules/, - use: [ - { - loader: 'babel-loader', - }, - { - loader: 'ts-loader', - }, - ], - }, +config.mode('production'); + +config + .entry('index') + .add(path.resolve(__dirname, 'src/app/service-worker.tsx')); + +config.devtool('source-map'); + +config.plugin('clean').use(CleanWebpackPlugin); + +config.plugin('copy').use(CopyPlugin, [ + { + patterns: [ { - test: /\.js(x?)$/, - exclude: /node_modules/, - use: [ - { - loader: 'babel-loader', - }, - ], + from: path.resolve(__dirname, 'public/'), + to: path.resolve(__dirname, 'dist/'), }, ], }, - resolve: { - extensions: ['*', '.js', '.jsx', '.ts', '.tsx'], - plugins: [PnpWebpackPlugin], - }, - resolveLoader: { - plugins: [PnpWebpackPlugin.moduleLoader(module)], - }, - optimization: { - runtimeChunk: 'single', - splitChunks: { - chunks: 'all', - cacheGroups: { - vendor: { - test: /[\\/]node_modules[\\/]/, - name: 'vendors', - chunks: 'all', - }, - }, - }, - }, - output: { - path: path.resolve(__dirname, 'dist/'), - filename: '[name].[hash].js', - chunkFilename: '[name].[hash].js', - publicPath: '/', +]); + +config.plugin('workbox').use(WorkboxPlugin.InjectManifest, [ + { + swSrc: path.resolve(__dirname, 'src/sw/sw.ts'), + maximumFileSizeToCacheInBytes: 15000000, }, - plugins: [ - new CleanWebpackPlugin(), - new HtmlWebpackPlugin(htmlCommonConfig), - new CopyPlugin({ - patterns: [ - { - from: path.resolve(__dirname, 'public/'), - to: path.resolve(__dirname, 'dist/'), - }, - ], - }), - new WorkboxPlugin.InjectManifest({ - swSrc: './src/sw/sw.ts', - maximumFileSizeToCacheInBytes: 15000000, - }), - ], -}; +]); -module.exports = config; +module.exports = config.toConfig(); -- cgit v1.2.3