forked from emiloberg/webpack-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
73 lines (66 loc) · 1.76 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
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HTMLWebpackPlugin = require('html-webpack-plugin');
const DEVELOPMENT = process.env.NODE_ENV === 'development';
const PRODUCTION = process.env.NODE_ENV === 'production';
const entry = PRODUCTION
? [
'./src/index.js'
]
: [
'./src/index.js',
'webpack/hot/dev-server',
'webpack-dev-server/client?http://localhost:8080'
];
const plugins = PRODUCTION
? [
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('style-[contenthash:10].css'),
new HTMLWebpackPlugin({
template: 'index-template.html'
})
]
: [
new webpack.HotModuleReplacementPlugin()
];
plugins.push(
new webpack.DefinePlugin({
DEVELOPMENT: JSON.stringify(DEVELOPMENT),
PRODUCTION: JSON.stringify(PRODUCTION)
})
);
const cssIdentifier = PRODUCTION ? '[hash:base64:10]' : '[path][name]---[local]';
const cssLoader = PRODUCTION
? ExtractTextPlugin.extract({
loader: 'css-loader?minimize&localIdentName=' + cssIdentifier
})
: ['style-loader', 'css-loader?localIdentName=' + cssIdentifier];
module.exports = {
devtool: 'source-map',
entry: entry,
plugins: plugins,
externals: {
jquery: 'jQuery' //jquery is external and available at the global variable jQuery
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: /node_modules/
}, {
test: /\.(png|jpg|gif)$/,
loaders: ['url-loader?limit=10000&name=images/[hash:12].[ext]'],
exclude: /node_modules/
}, {
test: /\.css$/,
loaders: cssLoader,
exclude: /node_modules/
}]
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: PRODUCTION ? '/' : '/dist/',
filename: PRODUCTION ? 'bundle.[hash:12].min.js' : 'bundle.js'
}
};