-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
115 lines (110 loc) · 2.98 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
var path = require('path');
var webpack = require('webpack');
var merge = require('webpack-merge');
var pkg = require('./package.json');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'src'),
build: path.join(__dirname, 'build')
};
/* Pass target environment (such as "start") to babel */
process.env.BABEL_ENV = TARGET;
/* Common settings for development and production */
var common = {
entry: PATHS.app + '/app.jsx',
module: {
preLoaders: [{
test: /\.jsx?$/,
include: PATHS.app,
loader: 'source-map'
}],
loaders: [{
test: /\.json?$/,
include: PATHS.app,
loaders: ['json-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
include: PATHS.app,
loaders: [
'url?limit=8192',
'img'
]
}, {
test: /\.jsx?$/,
include: PATHS.app,
loader: 'babel'
}]
},
plugins: [
new HtmlwebpackPlugin({
title: 'FINFO-UI',
template: 'index.html',
inject: 'body'
})
]
};
/* Development only settings. */
if (TARGET === 'webpack-dev-server' || !TARGET) {
module.exports = merge(common, {
entry: PATHS.app + '/app.jsx',
output: {
path: PATHS.build,
filename: 'bundle.js'
},
module: {
loaders: [{
test: /\.scss$/,
include: PATHS.app,
loaders: [
'style',
'css',
'autoprefixer?browsers=last 3 versions',
'sass?outputStyle=expanded'
]
}]
},
devtool: 'source-map',
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});
}
/* Production only settings. */
if (TARGET === 'build' || TARGET === 'stats') {
module.exports = merge(common, {
entry: {
app: PATHS.app + '/app.jsx',
vendor: Object.keys(pkg.dependencies)
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js',
publicPath: './build'
},
module: {
loaders: [{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css!sass?outputStyle=expanded', 'autoprefixer?browsers=last 3 versions', 'sass?outputStyle=expanded'),
include: PATHS.app
}]
},
plugins: [
new ExtractTextPlugin('styles.[chunkhash].css'),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
new webpack.DefinePlugin({
'process.env.NODE_ENT': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
})
};