首页 技术 正文
技术 2022年11月9日
0 收藏 773 点赞 2,359 浏览 1958 个字

打包后的目录结构:

webpack打包多个入口文件

webpack.config.js

// path 模块提供了一些用于处理文件路径
const path = require('path');
// fs模块用于对系统文件及目录进行读写操作
const fs = require('fs');
// 访问内置的插件
const webpack = require('webpack');
// cnpm install html-webpack-plugin --save-dev
const HtmlWebpackPlugin = require('html-webpack-plugin');
// cnpm install clean-webpack-plugin --save-dev
const CleanWebpackPlugin = require("clean-webpack-plugin");/**
* webpack配置
* @type {Object}
*/
const option = {};/**
* 入口
* @type {Object}
*/
option.entry = {};
/**
* 出口
* @type {Object}
*/
option.output = {};
// 打包根路径
option.output.path = path.resolve("./dist");
// 打包后js文件的相对路径
// option.output.filename = "js/[name]/index_[chunkhash:8].js";
option.output.filename = "js/[name].[chunkhash].js";
/**
* 打包类型
* @type {String}
*/
option.devtool = "eval-source-map";
/**
* 本地服务器配置
* @type {Object}
*/
option.devServer = {};
// 本地服务器根路径
option.devServer.contentBase = "./public";
// 是否记录历史
option.devServer.historyApiFallback = false;
// 是否实时刷新
option.devServer.inline = true;
// 监听端口
option.devServer.port = 8080;
/**
* 插件
* @type {Array}
*/
option.plugins = [];
// BannerPlugin插件
option.plugins.push(new webpack.BannerPlugin('版权所有,翻版必究'));
// 清除文件的CleanWebpackPlugin插件
option.plugins.push(new CleanWebpackPlugin(['dist/*.*','dist/js/*.js'],{
root:__dirname,
verbose:true,
dry:false
}));/**
* 测试多入口
* key值:打包后的文件name
* value值:源代码中的文件name
*/
option.entry.index = './src/main.js'; // => js/[name].[chunkhash].js => js/index.ff1e318532ae5fd984de.js
option.entry.a = './src/aa.js'; // => js/[name].[chunkhash].js => js/a.010a88238103e5fa9139.js
option.entry.b = './src/bb.js'; // => js/[name].[chunkhash].js => js/b.9f92cb4ee4ecd280c3af.js/**
* 测试多个html文件
* template : 源代码中的html文件
* filename : 打包后的html文件
* chunks : 要引入打包后的哪些js文件,从entry的key值里面找寻
*/
option.plugins.push(new HtmlWebpackPlugin({
template:'./src/aa/index.html',
filename:'aa_index.html',
chunks:['a']
}));
option.plugins.push(new HtmlWebpackPlugin({
template:'./src/bb/index.html',
filename:'bb_index.html',
chunks:['b']
}));
option.plugins.push(new HtmlWebpackPlugin({
template:'./src/index.html',
filename:'index.html',
chunks:['index','a','b']
}));//导出
module.exports = option;
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,287