Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.

Commit 09071db

Browse files
committed
将前端项目改为webpack-dev-server启动
1 parent 53a9cb5 commit 09071db

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

webpack.config.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,41 @@ var plugins = [
1818
// 该配置假定你引入的 vendor 存在于 node_modules 目录中
1919
return module.context && module.context.indexOf('node_modules') !== -1;
2020
}
21+
}),
22+
new webpack.DefinePlugin({
23+
// 定义全局变量
24+
'process.env':{
25+
'NODE_ENV': JSON.stringify(nodeEnv)
26+
}
2127
})
2228
]
23-
var app = [
24-
'babel-polyfill',
25-
'./src/index'
26-
]
29+
var app = ['./index']
2730
if (isPro) {
2831
plugins.push(
2932
new webpack.optimize.UglifyJsPlugin({
30-
compress: {
31-
warnings: false,
32-
drop_console: false
33-
}
34-
}),
35-
new webpack.DefinePlugin({
36-
// 定义全局变量
37-
'process.env':{
38-
'NODE_ENV': JSON.stringify(nodeEnv)
39-
}
33+
sourceMap: true,
34+
comments: false
4035
})
4136
)
4237
} else {
43-
app.push('webpack-hot-middleware/client?path=http://localhost:3011/__webpack_hmr&reload=true&noInfo=false&quiet=false')
38+
app.unshift('react-hot-loader/patch', 'webpack-dev-server/client?http://localhost:3011', 'webpack/hot/only-dev-server')
4439
plugins.push(
45-
new webpack.DefinePlugin({
46-
// 定义全局变量
47-
'process.env':{
48-
'NODE_ENV': JSON.stringify(nodeEnv)
49-
},
50-
BASE_URL: JSON.stringify('http://localhost:9009'),
51-
}),
52-
new webpack.HotModuleReplacementPlugin()
40+
new webpack.HotModuleReplacementPlugin(),
41+
new webpack.NamedModulesPlugin(),
42+
new webpack.NoEmitOnErrorsPlugin()
5343
)
5444
}
5545

5646
module.exports = {
57-
devtool: isPro ? 'source-map' : 'cheap-eval-source-map',
47+
context: path.resolve(__dirname, 'src'),
48+
devtool: isPro ? 'source-map' : 'inline-source-map',
5849
entry: {
5950
app: app
6051
},
6152
output: {
6253
filename: '[name].js',
6354
path: path.join(__dirname, 'build'),
64-
publicPath: isPro ? './build/' : 'http://localhost:3011/build/',
55+
publicPath: isPro ? './build/' : '/build/',
6556
chunkFilename: '[name].js'
6657
},
6758
// BASE_URL是全局的api接口访问地址
@@ -77,21 +68,31 @@ module.exports = {
7768

7869
module: {
7970
rules: [{
80-
test: /\.(js|jsx)$/,
81-
use: ['babel-loader'],
82-
exclude: /node_modules/,
83-
include: path.join(__dirname, 'src')
71+
test: /\.js$/,
72+
exclude: /(node_modules|bower_components)/,
73+
use: {
74+
loader: 'babel-loader?cacheDirectory=true'
75+
}
8476
}, {
8577
test: /\.(less|css)$/,
8678
use: ExtractTextPlugin.extract({
8779
use: ["css-loader", "less-loader", "postcss-loader"]
8880
})
8981
}, {
90-
test: /\.(png|jpg|gif|md)$/,
91-
use: ['file-loader?limit=10000&name=[md5:hash:base64:10].[ext]']
92-
}, {
93-
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
94-
use: ['url-loader?limit=10000&mimetype=image/svg+xml']
95-
}],
96-
}
82+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
83+
use: ['url-loader?limit=10000&name=files/[md5:hash:base64:10].[ext]']
84+
}]
85+
},
86+
devServer: {
87+
hot: true,
88+
compress: true,
89+
port: 3011,
90+
historyApiFallback: true,
91+
contentBase: path.resolve(__dirname),
92+
publicPath: '/build/',
93+
stats: {
94+
modules: false,
95+
chunks: false
96+
},
97+
},
9798
};

0 commit comments

Comments
 (0)