加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
33597248@qq.com 提交于 2018-12-07 17:17 . react-demo-master
/* global process,__dirname:true*/
const path = require("path");
const webpack = require("webpack");
// const EX = require("extract-text-webpack-plugin"); //css 单独打包
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); //css 单独打包
// const EXCSS = new EX('[name].css');
const env=process.env.NODE_ENV;
console.log("env",env);
const port="8081";
const entry={
vendor:["react","react-dom","react-router","react-router-dom","react-redux",
"redux-thunk","redux","lodash","natty-fetch-fd","nprogress","leaflet"],
index:"./src/app/app.js"
};
const mode= env?'production':'development';
const plugins= [
new MiniCssExtractPlugin({
filename: mode === 'development' ? '[name].css' : '[name].[hash].css',
chunkFilename: mode === 'development' ? '[id].css' : '[id].[hash].css',
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.ProvidePlugin({
React:"react"
}),
new webpack.DefinePlugin({
'__ENV__':JSON.stringify(env)
})
];
module.exports ={
mode:mode,
entry:entry,
output: {
filename: "[name].js",
path: path.resolve(__dirname,"dist")
},
performance:{
hints:false
},
optimization:{
splitChunks:{
cacheGroups:{
vendor:{
name:'vendor',
chunks:'initial',
minChunks:2
}
}
}
},
devServer: {
disableHostCheck: true,
// historyApiFallback:true,
hot: true,
inline: true, // 实时刷新
host: '0.0.0.0',
port,
/*devServe跨域代理配置*/
proxy:{
'/proxy':{
target:"http://localhost:8083",
pathRewrite:{'^/proxy':''},
changeOrigin:true,
secure:false
}
}
},
resolve: {
alias: {
'@':path.resolve(__dirname,'src')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: [
path.resolve(__dirname,'src')
],
loader: 'babel-loader'
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: "url-loader",
options: {
limit:8192
}
}
]
},
{
test: /\.(less|css)$/,
exclude: /node_modules/,
use: [
mode === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'less-loader'
],
}
/* ,{
test: /\.(less|css)$/,
exclude: /node_modules/,
use: EXCSS.extract({
fallback:'style-loader',
use:['css-loader','less-loader']
})
}*/
,{
test: /\.css$/,
exclude: /src/,
use: [
{
loader: "style-loader"
},{
loader: 'css-loader',
options: {
importLoaders:1
}
}
]
},{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "eslint-loader"
}
],
},
plugins
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化