-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathwebpack.config.js
47 lines (44 loc) · 1.85 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
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin'); //抽取CSS文件插件
var OpenBrowserPlugin = require('open-browser-webpack-plugin'); //自动打开浏览器插件
module.exports = {
// 配置服务器
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
contentBase: "./app", //最好写上,否则报错,难道这里是一个坑?
port: 8080
},
// 配置入口
entry: {
pages: __dirname +'/app/src/router.jsx',
vendors:['react','react-dom','react-router','reflux'] //第三方库和框架
},
output: {
// path: 'dist', //不写居然也没事,由于有服务器,生成不了静态文件,这也是一个坑
publicPath: 'dist',
filename: 'js/bundle.js',
},
module: {
loaders: [
{ test: /\.css$/, loader: ExtractTextPlugin.extract({fallbackLoader:'style-loader', loader:'css-loader'}) }, //坑:不能用叹号链接,必须写成这种格式
{ test: /\.less$/, loader: ExtractTextPlugin.extract('css-loader!less-loader') },
{ test: /\.js[x]?$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192&name=img/[name].[ext]' },
{ test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/, loader: 'url-loader' }
]
},
resolve: {
extensions: [' ', '.js', '.jsx'],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({'name':'vendors','filename':'js/vendors.js'}),
new ExtractTextPlugin("css/bundle.css"),
// 如需jquery请解锁
// new webpack.ProvidePlugin({ $: "jquery" }),
new webpack.HotModuleReplacementPlugin(),
new OpenBrowserPlugin({ url: 'http://localhost:8080/login' })
]
};