1 Star 4 Fork 0

humengqiao/个人webpack配置

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 3.45 KB
一键复制 编辑 原始数据 按行查看 历史
humengqiao 提交于 2018-05-13 10:55 . 初始化
const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const extractTextPlugin = require('extract-text-webpack-plugin');
const config= {
entry: {
main: ['./app.js'],
vendor: ['babel-polyfill', 'react', 'react-dom', 'vue']
},
output: {
filename: '[name].[hash:6].js',
path: path.resolve(__dirname, './build')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.styl$/,
use: extractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
localIdentName: '[name]__[local]--[hash:base64:5]',
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
config: {
path: 'postcss.config.js'
}
}
},
'stylus-loader'
]
})
},
{
test: /\.css$/,
use: extractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader']
})
},
{
test: /\.vue$/,
exclude: /node_modules/,
use: [
{
loader: 'vue-loader'
}
]
}
]
},
resolve: {
extensions: [' ', '.js', '.jsx', '.vue'],
alias: {
'vue': 'vue/dist/vue.esm.js'
}
},
plugins: [
new htmlWebpackPlugin({
template: './tpl.html',
title: 'webpack devserver demo',
inject: true
}),
new webpack.HotModuleReplacementPlugin(),
new extractTextPlugin('[name].css'),
new webpack.NamedModulesPlugin()
],
devtool: '#eval-source-map',
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
minChunks: 2,
maxInitialRequests: 5,
minSize: 0,
name: 'vendor'
}
}
},
runtimeChunk: {
name: 'manifest'
}
}
}
if(process.NODE_ENV === 'production') {
config.plugins.push(
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./build/vendor-manifest.json')
})
)
}else {
config.devServer = {
contentBase: path.resolve(__dirname, 'build'),
port: 8080,
bonjour: true,
historyApiFallback: true,
index: 'index.html',
hot: true,
inline: true,
overlay: true,
compress: true
}
}
module.exports = config
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/humengqiao/personal_webpack_configuration.git
[email protected]:humengqiao/personal_webpack_configuration.git
humengqiao
personal_webpack_configuration
个人webpack配置
master

搜索帮助