const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const {CleanWebpackPlugin} = require('clean-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
const commonCssLoader = [ { loader: MiniCssExtractPlugin.loader, options: { publicPath: '../' } }, 'css-loader', { loader: "postcss-loader", options: { ident: 'postcss', plugins: () => [ require('postcss-preset-env')() ] } } ];
module.exports = { entry: './src/index.js', output: { filename: "main.[contenthash:10].js", path: path.resolve(__dirname, 'dist'), }, optimization: { splitChunks: { chunks: "all", minSize: 30*1024, } }, mode: "development", resolve: { alias: { $css: path.resolve(__dirname,'src/css') }, extensions: ['js','json','vue'], modules: [path.resolve(__dirname,'./node_modules'),'node_modules'] }, devServer: { contentBase: path.resolve(__dirname, 'dist'), watchContentBase: true, watchOptions:{ ignored: /node_modules/ }, compress: true, port: 8080, open: true, hot: true, }, module: { rules: [ { test: /\.css$/, use: [ ...commonCssLoader ], }, { test: /\.less$/, use: [ ...commonCssLoader, 'less-loader' ] }, { test: /\.jpg|png$/, loader: 'url-loader', options: { limit: 8 * 1024, esModule: false, name: '[hash:10].[ext]', outputPath: 'imgs' } }, { test: /\.html$/, loader: 'html-loader' }, { test: /\.js$/, exclude: /node_modules/, include: path.resolve(__dirname,'src'), enforce: "pre", loader: 'eslint-loader', options: { fix: true } }, { test: /\.js$/, exclude: /node_modules/, use: [ ], loader: 'babel-loader', options: { presets: [ [ '@babel/preset-env', { useBuiltIns: 'usage', corejs: { version: 3 }, targets: { chrome: '60', firefox: '60', ie: '9', safari: '10', edge: '17' } } ] ], cacheDirectory: true } } ], }, plugins: [ new CleanWebpackPlugin(), new HtmlWebpackPlugin({ template: './src/index.html', minify: { collapseWhitespace: true, removeComments: true } }), new MiniCssExtractPlugin({ filename: 'css/[name].[contenthash:10].css' }), new OptimizeCssAssetsWebpackPlugin(), ] };
|