1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16const {merge} = require('webpack-merge'); 17const configCommon = require('./webpack.config.common'); 18const path = require('path'); 19const HtmlWebpackPlugin = require('html-webpack-plugin'); 20const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin'); 21 22const configProd = { 23 mode: 'production', 24 entry: { 25 polyfills: './src/polyfills.ts', 26 styles: ['./src/material-theme.scss', './src/styles.css'], 27 app: './src/main_prod.ts', 28 }, 29 output: { 30 path: path.resolve(__dirname, 'dist/prod'), 31 publicPath: '/', 32 filename: 'js/[name].[hash].js', 33 chunkFilename: 'js/[name].[id].[hash].chunk.js', 34 }, 35 optimization: { 36 runtimeChunk: 'single', 37 splitChunks: { 38 chunks: 'all', 39 maxInitialRequests: Infinity, 40 minSize: 0, 41 cacheGroups: { 42 vendor: { 43 test: /[\\/]node_modules[\\/]/, 44 name(module) { 45 const packageName = module.context.match( 46 /[\\/]node_modules[\\/](.*?)([\\/]|$)/, 47 )[1]; 48 return `npm.${packageName.replace('@', '')}`; 49 }, 50 }, 51 styles: { 52 test: /\.css$/, 53 name: 'styles', 54 chunks: 'all', 55 enforce: true, 56 }, 57 }, 58 }, 59 }, 60 plugins: [ 61 new HtmlWebpackPlugin({ 62 template: 'src/index.html', 63 inject: 'body', 64 inlineSource: '.(css|js)$', 65 }), 66 new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin), 67 ], 68}; 69 70module.exports = merge(configCommon, configProd); 71