zoukankan      html  css  js  c++  java
  • 利用webpack 打包多页应用

    利用webpack打包多页应用

    • 要点
      • 定义多个入口文件
      • 定义多个出口文件' [name].js'
      • 利用html-webpack-plugin
        • 如果有个多个文件,则需要多次new 这个插件,需要在插件中配置chunks
    const path = require('path')
    const HtmlWebpackPlugin = require("html-webpack-plugin")
    const { CleanWebpackPlugin } = require('clean-webpack-plugin')
    const webpack = require('webpack')
    
    /**
     *  1. 多个入口, 多个出口, 多个html
     */
    
    module.exports = {
        mode: 'development',
        // 多入口
        entry: {
            home: __dirname + '/src/index.js',
            other: __dirname + '/src/other.js'
        },
        // 两个入口打包, 需要对应的多个出口, 产生多个html
        output: {
            path: path.resolve(__dirname, 'dist'),
            filename: '[name][hash:4].js'
        },
        devServer: {
            contentBase: '/public',
            hot: true,
            port: 8000
        },
        module: {
            rules: [
                {
                    test: /.css$/i,
                    use: ['style-loader', 'css-loader']
                },
                {
                    test: /.less$/i,
                    use: ['style-loader', 'css-loader', 'less-loader']
                }
            ]
        },
        // new 两次拆建
        plugins: [
            new HtmlWebpackPlugin({
                title: '龙风的测试店铺',
                template: __dirname + '/public/index.html',
                filename: 'home.html',
                chunks: ['home']
            }),
            new HtmlWebpackPlugin({
                title: '龙风的测试店铺',
                template: __dirname + '/public/index.html',
                filename: 'other.html',
                chunks: ['other']
            }),
            new CleanWebpackPlugin(),
            new webpack.HotModuleReplacementPlugin()
        ]
    }
    
  • 相关阅读:
    实现ls(课上作业)
    20181217 (2)
    20181217 (1)
    ubuntu开启远程ssh登陆本机功能
    解决ubuntu下Could not get lock的问题
    博客园生成目录结构
    np.mean以及np.std用法
    解决 Could not find a version that satisfies the requirement torch==1.4.0
    github下载ocr模型 windows直接解压出问题
    centos7 连接不上网络解决办法
  • 原文地址:https://www.cnblogs.com/yaogengzhu/p/13556699.html
Copyright © 2011-2022 走看看