123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- const path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
- const TerserJSPlugin = require('terser-webpack-plugin')
- const webpack = require('webpack');
- const htmlPlugin = new HtmlWebpackPlugin({
- template: './src/index.html',
- filename: 'index.html',
- hash: true,
- minify: {
- removeAttributeQuotes: true,
- collapseWhitespace: true
- },
- chunks: ['index']
- });
- const aboutPlugin = new HtmlWebpackPlugin({
- template: './src/about.html',
- filename: 'about.html',
- hash: true,
- minify: {
- removeAttributeQuotes: true,
- collapseWhitespace: true
- },
- chunks: ['about']
- });
- const miniPlugin = new MiniCssExtractPlugin({
- filename: 'main.css'
- });
- const webpackProvidePlugin = new webpack.ProvidePlugin({
- $: 'jquery',
- })
- module.exports = {
- optimization: {
- minimize: true,
- minimizer: [
- new TerserJSPlugin({
- terserOptions: {
- output: {
- comments: false
- }
- },
- extractComments: false,
- sourceMap: true
- }),
- new OptimizeCSSAssetsPlugin()
- ]
- },
- devServer: {
-
-
- contentBase: path.resolve(__dirname, './build'),
- open: true,
- host: process.env.HOST || '192.168.1.66',
- port: 3000
- },
- mode: 'development',
- entry: {
- index: './src/index.js',
- about: './src/about.js'
- },
- output: {
- filename: '[name].bundle.js',
- path: path.resolve(__dirname, 'dist'),
- },
- plugins: [
- miniPlugin,
- htmlPlugin,
- aboutPlugin,
- webpackProvidePlugin
- ],
- module: {
- rules: [{
- test: /\.(html)$/,
- use: {
- loader: 'html-loader',
- options: {
- attrs: ['img:src', 'img:data-src', 'audio:src'],
-
- }
- }
- },
- {
- test: /\.(png|jpg)$/,
- use: [{
- loader: 'url-loader',
- options: {
- limit: 1,
- esModule: false,
- outputPath: 'img/'
- }
- }]
- },
- {
- test: /\.js$/,
- use: {
- loader: 'babel-loader',
- options: {
- presets: [
- '@babel/preset-env'
- ]
- }
- },
- include: path.resolve(__dirname, 'src'),
- exclude: /node_modules/
- },
- {
- test: /\.css$/,
- use: [
- MiniCssExtractPlugin.loader,
- 'css-loader',
- 'postcss-loader'
- ]
- },
- {
- test: /\.less$/,
- use: [
- MiniCssExtractPlugin.loader,
- 'css-loader',
- 'less-loader',
- 'postcss-loader',
- ]
- }
- ]
- }
- }
|