-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
executable file
·122 lines (115 loc) · 3.64 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
/**
* WEBPACK CONFIG
*
* Notes on config properties:
*
* 'entry'
* Entry point for the bundle.
*
* 'output'
* If you pass an array - the modules are loaded on startup. The last one is exported.
*
* 'resolve'
* Array of file extensions used to resolve modules.
*
* 'webpack-dev-server'
* Is a little node.js Express server, which uses the webpack-dev-middleware to serve a webpack bundle.
* It also has a little runtime which is connected to the server via Socket.IO.
*
* 'webpack/hot/dev-server'
* By adding a script to your index.html file and a special entry point in your configuration
* you will be able to get live reloads when doing changes to your files.
*
* devtool: 'eval-source-map'
* http://www.cnblogs.com/Answer1215/p/4312265.html
* The source map file will only be downloaded if you have source maps enabled and your dev tools open.
*
* HotModuleReplacementPlugin()
* Hot Module Replacement (HMR) exchanges, adds or removes modules while an application is running without page reload.
*
* NoErrorsPlugin()
* Hot loader is better when used with NoErrorsPlugin and hot/only-dev-server since it eliminates page reloads
* altogether and recovers after syntax errors.
*
* 'react-hot'
* React Hot Loader is a plugin for Webpack that allows instantaneous live refresh without losing state
* while editing React components.
*
* 'babel'
* Babel enables the use of ES6 today by transpiling your ES6 JavaScript into equivalent ES5 source
* that is actually delivered to the end user browser.
*/
/* eslint-disable no-var */
var webpack = require('webpack');
var path = require('path');
var styleFileLoader = 'file?name=assets/styles/[name]-[hash].css';
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:5000',
'webpack/hot/dev-server',
'./app/index'
],
output: {
path: __dirname,
filename: 'bundle.js',
publicPath: '/static/'
},
resolve: {
extensions: ['', '.jsx', '.js']
},
devtool: 'eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{ test: /\.css$/, loader: "style-loader!css-loader" },
{
test: /\.(png|jpg|gif)$/,
loader: 'url?limit=8192&name=[name]-[hash].[ext]'
},
{
test: /\.scss$/,
loaders: [
// styleFileLoader,
// 'resolve-url',
// 'style',
'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
'sass?sourceMap'
]
},
{test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
{
loader: "babel",
// Only run `.js` and `.jsx` files through Babel
test: /\.jsx?$/,
// Skip any files outside of your project's `src` directory
include: [
path.resolve(__dirname, "app"), path.resolve(__dirname)
],
exclude: /node_modules/,
// Options to configure babel with
query: {
"presets": ["es2015", "stage-0", "react"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
}]
]
}
}
}
},
]
},
};