-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
136 lines (130 loc) · 3.45 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* 默认使用蚂蚁金服 antd组件,如果不需要antd的话,就需要修改js的loader
* @type {webpack}
*/
const webpack = require('webpack');
const path = require('path');
const env = require('./Env/env');
const nodeModelDir = path.join(__dirname, 'node_modules');
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
// const HtmlwebpackPlugin = require('html-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
// process.env.NODE_ENV
const deps = [
'react/dist/react.min.js',
'react-router/dist/react-router.min.js',
'moment/min/moment.min.js',
'underscore/underscore-min.js',
'antd/dist/antd.min.js',
'lodash/lodash.js',
];
// 引用环境属性,根据profile属性来修改webpack属性
const envPlugin = new webpack.DefinePlugin({ __ENV__: JSON.stringify(env) });
const config = {
entry: {
app: ['babel-polyfill', './App/index.jsx'],
},
output: {
path: path.resolve(__dirname, './build'),
filename: '[name].js',
},
resolve: {
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
alias: [],
},
// externals: {
// react: 'React',
// 'react-dom': 'ReactDOM',
// _: 'lodash',
// antd: 'antd',
// },
plugins: [
envPlugin,
// 生成 index.html 插件
// , new HtmlwebpackPlugin({
// D:\\nodeJs\\ title: 'Webpack-demos',
// filename: 'index.html'
// })
new LodashModuleReplacementPlugin(),
// 提取公用js插件
// new webpack.optimize.CommonsChunkPlugin({
// name: "common",
// filename: "js/common.js",
// chunks: ['index', 'detail']
// })
],
module: {
loaders: [
{
test: /\.(css)$/,
loaders: ['style-loader', 'css-loader?modules&localIdentName=[local]-[hash:base64:5]', 'less-loader'],
},
{
test: /\.(less)$/,
loader: 'style-loader!css-loader!less-loader',
},
{
test: /\.(jpg|png)$/,
loader: 'url-loader?limit=8192',
},
{
test: /\.(eot|svg|ttf|woff|woff2)\w*/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: '/node_modules/',
query: {
presets: ['es2015', 'stage-0', 'react'],
plugins: [['import', {
libraryName: 'antd',
style: true, // or 'css'
}]],
},
},
],
noParse: [],
},
};
// 开发者模式
if (process.env.NODE_ENV === 'develop') {
// 热响应插件
config.plugins.push(new webpack.HotModuleReplacementPlugin());
// 弹出界面插件
config.plugins.push(
new OpenBrowserPlugin({
url: 'http://localhost:9999',
}));
// "source-map";// #eval-
config.devtool = 'source-map';
// 代理设置
config.devServer = {
port: 9999,
proxy: {
'/api/*': {
host: 'localhost',
target: 'http://localhost:8080/api',
secure: false,
withCredentials: true,
pathRewrite: {
'^/api/': '',
},
},
},
};
} else {
config.plugins.push(new UglifyJsPlugin({
compress: {
warnings: false,
},
sourceMap: false,
}));
}
deps.forEach((dep) => {
const depPath = path.resolve(nodeModelDir, dep);
config.resolve.alias[dep.split(path.sep)[0]] = depPath;
config.module.noParse.push(depPath);
});
module.exports = config;