-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·113 lines (106 loc) · 3.33 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
var path = require('path');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var merge = require('webpack-merge');
var webpack = require('webpack');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var CleanWebpackPlugin = require('clean-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = require('./app.config');
var BabiliPlugin = require("babili-webpack-plugin");
var CompressionPlugin = require('compression-webpack-plugin');
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build')
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: PATHS.app,
output: {
path: PATHS.build,
filename: 'bundle.[hash].js'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
sassResources: [
'./app/scss/_variables.scss',
'./app/scss/_mixins.scss',
],
module: {
preLoaders: [
],
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
include: PATHS.app
}, {
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.app
},{
test: /\.scss$/,
loader: TARGET === 'build' ?
ExtractTextPlugin.extract('style-loader', 'css-loader?minimize!sass-loader!sass-resources') :
'style!css!sass!sass-resources',
include: PATHS.app
},{
test: /\.(png|jpg|svg|woff2)$/,
loader: "file-loader"
},{
test: /manifest.json$/,
loader: 'file-loader?name=manifest.json!web-app-manifest-loader'
}
]
},
plugins: [
new HtmlwebpackPlugin({
title: config.PAGE_TITLE,
template: "app/assets/index.html",
appMountId: 'app',
hash: false,
mobile: true,
themeColor: config.THEME_COLOR,
sentry: TARGET === 'build' ? config.SENTRY_KEY : false,
sw: TARGET === 'build' ? true : false,
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: TARGET === 'build' ? JSON.stringify("production") : JSON.stringify("development")
}
}),
]
};
// Default configuration
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: config.SERVER_HOST,
port: config.SERVER_PORT
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
]
});
}
if (TARGET === 'build') {
module.exports = merge(common, {
plugins: [
new BabiliPlugin(),
new webpack.optimize.DedupePlugin(),
new CleanWebpackPlugin(['build']),
new ExtractTextPlugin("styles.[hash].css"),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
]
});
}