| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- const path = require('path')
- const webpack = require('webpack')
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const WebpackMerge = require('webpack-merge')
- const baseConfig = require('./webpack.base.js')
- module.exports = WebpackMerge.merge(baseConfig, {
- mode: 'production',
- //开发环境下默认启用cache,在内存中对已经构建的部分进行缓存
- //避免其他模块修改,但是该模块未修改时候,重新构建,能够更快的进行增量构建
- //属于空间换时间的做法
- cache: true,
- // 代码入口
- entry: {
- // 注册界面
- main: './src/index.js',
- },
- output: {
- path: path.resolve(__dirname, './dist'),
- publicPath: './',
- filename: './eam-app-v3-js-bundle/[name].[contenthash:8].js',
- chunkFilename: './eam-app-v3-js-chunk/[name].[contenthash:8].js',
- },
-
- optimization: {
- minimize: true, // 压缩 bundle
- splitChunks: {
- // include all types of chunks
- chunks: 'all',
- name: false,
- minSize: 30000,
- maxSize: 500000,
- cacheGroups: {
- common: {
- test: /[\\/]node_modules[\\/]/,
- name: 'common',
- chunks: 'initial',
- priority: 2,
- minChunks: 2,
- },
- }
- },
- },
- //devtool: 'source-map', // 打包不需要 source-map
- plugins: (module.exports.plugins || []).concat([
- new HtmlWebpackPlugin({
- title: 'Prodog App',
- template: './static-eam-app/index.html', // 源模板文件
- filename: './app.html', // 输出文件【注意:这里的根路径是module.exports.output.path】
- chunks: ['main']
- }),
- new webpack.LoaderOptionsPlugin({
- minimize: true
- }),
- // CSS 提取
- new MiniCssExtractPlugin({
- filename: "./eam-app-v3-style/[name].[contenthash:8].css"
- }),
- ])
- })
|