加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 3.54 KB
一键复制 编辑 原始数据 按行查看 历史
abzuoyou 提交于 2021-02-24 20:39 . initialize project
const path = require('path');
const uglify = require('uglifyjs-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const config = {
mode: 'production', // development
entry: {
index: path.resolve(__dirname, './src/js/Index.js'),
list: path.resolve(__dirname, './src/js/List.js'),
detail: path.resolve(__dirname, './src/js/Detail.js'),
cart: path.resolve(__dirname, './src/js/Cart.js'),
order: path.resolve(__dirname, './src/js/Order.js')
},
//devtool: 'inline-source-map', // 加上对应的配置
output: {
path: path.resolve(__dirname + '/dist'),
filename: 'js/[name].js'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: path.resolve(__dirname, 'node_modules'),
query: {
'presets': ['latest']
}
},
{
test: /\.tpl$/,
loader: 'ejs-loader'
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: function () {
return [autoprefixer('last 5 versions')]
}
}
},
'sass-loader'
]
},
{
test: /\.css$/,
loader: 'css-loader'
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/i,
loader: [
'url-loader?limit=1024&name=img/[name]-[hash:16].[ext]',
'image-webpack-loader'
]
}
]
},
plugins: [
new uglify(),
new htmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true
},
filename: 'index.html',
template: path.resolve(__dirname, 'src/index.html'),
title: '小米手机官网',
chunksSortMode: 'manual',
chunks: ['index'],
excludeChunks: ['node_modules'],
hash: true
}),
new htmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true
},
filename: 'list.html',
template: path.resolve(__dirname, 'src/list.html'),
title: '小米手机详情',
chunksSortMode: 'manual',
chunks: ['list'],
excludeChunks: ['node_modules'],
hash: true
}),
new htmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true
},
filename: 'detail.html',
template: path.resolve(__dirname, 'src/detail.html'),
title: '小米页面机型详情',
chunksSortMode: 'manual',
chunks: ['detail'],
excludeChunks: ['node_modules'],
hash: true
}),
new htmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true
},
filename: 'cart.html',
template: path.resolve(__dirname, 'src/cart.html'),
title: '购物车',
chunksSortMode: 'manual',
chunks: ['cart'],
excludeChunks: ['node_modules'],
hash: true
}),
new htmlWebpackPlugin({
minify: {
removeComments: true,
collapseWhitespace: true
},
filename: 'order.html',
template: path.resolve(__dirname, 'src/order.html'),
title: '购买',
chunksSortMode: 'manual',
chunks: ['order'],
excludeChunks: ['node_modules'],
hash: true
})
// new miniCssExtractPlugin({
// filename: 'css/[name].css'
// })
],
devServer: {
watchOptions: {
ignored: /node_modules/
},
open: true,
host: 'localhost',
port: 3338
},
};
module.exports = config;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化