-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.babel.js
76 lines (71 loc) · 2.16 KB
/
webpack.config.babel.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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
const config = {
entry: {
app: [
'./src/index.scss',
'babel-polyfill',
'./src/index.js',
],
},
module: {
preLoaders: [
{ test: /\.js$/, exclude: [/node_modules/], loader: 'eslint-loader' },
],
loaders: [
{ test: /\.js$/, exclude: [/node_modules/], loader: 'babel' },
{ test: /\.html$/, loader: 'html' },
{ test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css!autoprefixer!sass') },
{ test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css') },
{
test: /\.(gif|png|jpe?g|svg|webp|woff|woff2|ttf|eot|mp3|mp4|webm)(\?.+)?$/,
loader: 'file?name=[sha512:hash:base36:7].[ext]',
},
],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.Tether': 'tether',
}),
// Injects bundles in your index.html instead of wiring all manually.
// It also adds hash to all injected assets so we don't have problems
// with cache purging during deployment.
new HtmlWebpackPlugin({
template: 'src/index.html',
inject: true,
hash: true,
}),
new ExtractTextPlugin('index.css', { disable: NODE_ENV !== 'production' }),
],
};
if (NODE_ENV === 'development') {
config.output = {
filename: '[name].bundle.js',
publicPath: '/',
path: path.resolve(__dirname, 'src'),
};
} else if (NODE_ENV === 'production') {
config.output = {
filename: '[name].bundle.js',
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
};
config.plugins = config.plugins.concat([
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
minChunks: module => module.resource && module.resource.indexOf('node_modules') !== -1,
}),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$super', '$', 'exports', 'require'],
},
}),
]);
}
module.exports = config;