1 Star 0 Fork 0

CC3688/webpack-demo

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
webpack.pub.config.js 2.36 KB
Copy Edit Raw Blame History
CC3688 authored 2018-12-22 11:11 . finshed product webpack config
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
//导入每次删除文件夹的插件
const cleanWebpackPlugin = require('clean-webpack-plugin')
//导入抽取css样式的插件
const ExtractTextPlugin = require('extract-text-webpack-plugin')
//导入压缩css样式的插件
const optimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
module.exports ={
mode:'production',
entry: {
app: path.join(__dirname, './src/main.js'),
vendors: ['jquery'] //把要抽离的第三方名称,放到这个数组中
},
output: {
path: path.join(__dirname, './dist'),
filename: 'js/[name].[hash:6].bundle.js'
},
plugins: [
new htmlWebpackPlugin({
template: path.join(__dirname, './src/index.html'),
filename: 'index.html',
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
}
}),
new cleanWebpackPlugin(['dist']),
new ExtractTextPlugin('css/[name].css'),
new optimizeCssAssetsPlugin
],
optimization: {
splitChunks: {
cacheGroups: {
vendors:{
test: /node_modules/,
chunks: "initial",
name: "vendors",
},
}
}
},
module:{
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader',
publicPath: '../' //指定抽取的时候,自动为路径加上 ../前缀
})
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader','sass-loader'],
publicPath: '../' //指定抽取的时候,自动为路径加上 ../前缀
})
},
{
test: /\.(png|gif|bmp|jpg|jpeg)$/,
use: ['url-loader?limit=5000&name=images/[hash:8]-[name].[ext]']
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
]
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CC3688/webpack-demo.git
git@gitee.com:CC3688/webpack-demo.git
CC3688
webpack-demo
webpack-demo
master

Search