美文网首页
webpack4个人学习详细笔记(七)--打包多页应用

webpack4个人学习详细笔记(七)--打包多页应用

作者: gem_Y | 来源:发表于2020-03-29 12:21 被阅读0次

1. 新建一个项目

yarn init -y
yarn add webpack webpack-cli -D
yarn add html-webpack-plugin -D

webpack.config.js

let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: {
    home: './src/index.js',
    other: './src/other.js'
  },
  output: {
    // [name] : 代表home/other
    filename: '[name].[hash:8].js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      filename: 'home.html',
      chunks: ['home'] // 引入home.js
    }),
    new HtmlWebpackPlugin({
      template: './src/index.html',
      filename: 'other.html',
      chunks: ['other', 'home'] // 引入other.js 和 home.js
    }),
  ],
}

相关文章

网友评论

      本文标题:webpack4个人学习详细笔记(七)--打包多页应用

      本文链接:https://www.haomeiwen.com/subject/mabyuhtx.html