美文网首页
记录一下webpack4 配置多页面

记录一下webpack4 配置多页面

作者: 丶维她命 | 来源:发表于2019-11-26 13:33 被阅读0次

    webpack.config.js中配置

    const path = require("path");
    const HtmlWebpackPlugin = require("html-webpack-plugin");
    const CleanWebpackPlugin = require("clean-webpack-plugin");
    
    const plugin = [
      new HtmlWebpackPlugin({
        filename: "admin.html",
        template: `src/admin/index.html`,
        chunks: ["admin"],
        inject: true,
        minify: {
          removeComments: true,
          collapseWhitespace: true
        }
      }),
      new HtmlWebpackPlugin({
        filename: "mobile.html",
        template: `src/mobile/index.html`,
        chunks: ["mobile"],
        inject: true,
        minify: {
          removeComments: true,
          collapseWhitespace: true
        }
      })
    ];
    
    module.exports = {
      // 输入
      entry: {
        admin: path.resolve(__dirname, `src/admin/index.js`),
        mobile: path.resolve(__dirname, `src/mobile/index.js`)
      },
      // 输出
      output: {
        filename: `[name].[hash].js`,
        path: path.resolve(__dirname, `dist`),
        publicPath: ``
      },
      plugins: [
        ...plugin,
        new CleanWebpackPlugin(["dist"]),
      ],
      module: {
        rules: []
      },
    };
    

    相关文章

      网友评论

          本文标题:记录一下webpack4 配置多页面

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