-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathwebpack.config.dev.js
59 lines (57 loc) · 2.04 KB
/
webpack.config.dev.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
const webpack = require('webpack');
const path = require('path');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DashboardPlugin = require('webpack-dashboard/plugin');
const config = {
devtool: "source-map", // or "inline-source-map"
entry: [
'webpack/hot/dev-server',
'webpack-dev-server/client?http://localhost:8080',
path.resolve(__dirname, 'app/index.js') // 定义入口文件
],
output: { // 定义出口目录
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
publicPath: 'http://localhost:8080/' // html引用路径
},
resolve: { // resolve 指定可以被 import 的文件后缀
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.js|jsx$/, // 检测哪些文件需要此loader,是一个正则表达式,用正则来匹配文件路径,这段意思是匹配 js 或者 jsx
exclude: /(node_modules|bower_components)/,
loaders: ['babel'] // 加载模块 "babel" 是 "babel-loader" 的缩写
},
{
test: /(\.css|\.scss)$/,
loaders: ["style", "css?sourceMap", "sass?sourceMap"]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'url?limit=10000&name=img/[hash:8].[name].[ext]',
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.tpl.html',
inject: 'body',
filename: 'index.html'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__DEV__: JSON.stringify(JSON.parse(process.env.DEBUG || 'false'))
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new OpenBrowserPlugin({ url: 'http://localhost:8080/' }),
new DashboardPlugin()
]
};
module.exports = config;