123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- const path = require('path')
- const webpack = require('webpack')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const config = require('../config')
- const VueLoaderPlugin = require('vue-loader/lib/plugin')
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
- const TerserPlugin = require('terser-webpack-plugin')
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
- module.exports = {
- mode: 'production',
- entry: path.resolve(__dirname, '../../src/index.js'),
- output: {
- path: path.resolve(__dirname, '../../dist'),
- filename: 'assets/scripts/[name].[chunkhash:8].js',
- publicPath: config.prod.publicPath,
- },
- module: {
- rules: [
- {
- test: /\.css$/i,
- use: [
- MiniCssExtractPlugin.loader,
- {
- loader: 'css-loader',
- options: {
- importLoaders: 1,
- },
- },
- 'postcss-loader',
- ],
- },
- {
- test: /\.s[ac]ss$/i,
- use: [
- MiniCssExtractPlugin.loader,
- {
- loader: 'css-loader',
- options: {
- importLoaders: 2,
- },
- },
- 'postcss-loader',
- 'sass-loader',
- ],
- },
- {
- test: /\.(png|jpe?g|gif|svg)$/i,
- loader: 'file-loader',
- options: {
- name: 'assets/images/[name].[contenthash:8].[ext]',
- },
- },
- {
- test: /\.js$/,
- enforce: 'pre',
- exclude: /node_modules/,
- loader: 'eslint-loader',
- },
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loader: 'babel-loader',
- },
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- },
- ],
- },
- optimization: {
- minimize: true,
- minimizer: [
- new TerserPlugin({
- terserOptions: {
- parse: {
- ecma: 8,
- },
- compress: {
- drop_console: true,
- },
- mangle: {
- safari10: true,
- },
- },
- cache: true,
- parallel: true,
- }),
- new OptimizeCSSAssetsPlugin(),
- ],
- splitChunks: {
- chunks: 'all',
- maxSize: 224000,
- cacheGroups: {
- vendors: {
- test: /[\\/]node_modules[\\/]/,
- name: 'vendors',
- },
- },
- },
- },
- externals: {
- vue: 'Vue',
- },
- resolve: {
- extensions: [
- '.js',
- '.vue',
- ],
- alias: {
- '@': path.resolve(__dirname, '../../src'),
- },
- },
- devtool: 'inline-source-map',
- plugins: [
- new HtmlWebpackPlugin({
- template: config.template,
- inject: true,
- minify: {
- collapseWhitespace: true,
- removeAttributeQuotes: true,
- removeComments: true,
- },
- }),
- new VueLoaderPlugin(),
- new webpack.HashedModuleIdsPlugin(),
- new webpack.DefinePlugin({
- 'process.env': config.prod.env,
- }),
- new MiniCssExtractPlugin({
- filename: 'assets/styles/[name].[contenthash:8].css',
- chunkFilename: 'assets/styles/[name].[contenthash:8].chunk.css',
- }),
- ],
- }
|