forked from ap13p/react-boillerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (98 loc) · 2.8 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
'use strict';
const path = require('path')
const webpack = require('webpack')
const autoprefixer = require('autoprefixer')
const WebpackHtmlPlugin = require('html-webpack-plugin')
const OfflinePlugin = require('offline-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const packageJson = require('./package.json')
const getPath = (_path) => path.resolve(path.join(__dirname, _path))
const config = {
devtool: '#source-map',
context: getPath('src'),
entry: {
vendor: Object.keys(packageJson.dependencies),
app: [ getPath('src/index.js') ],
},
output: {
path: getPath('./dist/'),
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js',
publicPath: '/',
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'chunk',
async: true,
}),
new webpack.EnvironmentPlugin([
'NODE_ENV',
'BUILD_ENV',
]),
new webpack.optimize.DedupePlugin(),
new WebpackHtmlPlugin({
title: 'React Boillerplate',
template: getPath('src/index.html'),
minify: false,
}),
new webpack.optimize.OccurenceOrderPlugin(),
],
module: {
loaders: [
{ test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/ },
{ test: /\.jpe?g$|\.gif$|\.png$/i, loader: 'url?limit=10000', exclude: /node_modules/ },
{ test: /\.json$/, loader: 'json' },
],
preLoaders: [
{ test: /\.jsx?$/, loader: 'jscs', exclude: /node_modules/, },
],
},
jscs: {
emitErrors: false,
failOnHint: false,
},
postcss: () => [autoprefixer({ browsers: ['android > 4', 'IE > 9'] })],
resolve: {
extensions: [
'',
'.js',
'.jsx',
'.json',
'.scss',
'.css',
],
root: [
getPath('src'),
],
},
};
if (process.env.NODE_ENV === 'development') {
config.entry.app.unshift('webpack-hot-middleware/client?http://localhost:9019');
config.devtool = '#eval';
config.module.loaders.push({
test: /\.scss/,
loader: 'style!css!postcss!sass',
})
config.plugins.unshift(new webpack.HotModuleReplacementPlugin());
}
if (process.env.NODE_ENV === 'production') {
config.output.filename = '[chunkhash].js';
config.output.chunkFilename = '[id]-[chunkhash].js';
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}))
config.plugins.push(new webpack.optimize.AggressiveMergingPlugin())
config.module.loaders.push({
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css!postcss!sass'),
exclude: /node_modules/
})
config.plugins.push(new ExtractTextPlugin('[chunkhash].css'))
config.plugins.push(new OfflinePlugin({
AppCache: { directory: './' },
excludes: ['/', 'index.html'],
}));
}
module.exports = config;