Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
109 lines (104 loc) · 2.43 KB
/
Copy pathwebpack.config.js
File metadata and controls
109 lines (104 loc) · 2.43 KB
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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const merge = require('webpack-merge');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
css: [
path.join(__dirname, 'app'),
path.join(__dirname, 'node_modules/purecss')
]
};
process.env.BABEL_ENV = TARGET;
var common = {
entry: PATHS.app,
resolve: {
extensions: ['', '.js', '.jsx', '.css'],
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
include: [PATHS.app]
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'Reports application'
})
]
};
if(TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.css
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}),
new webpack.HotModuleReplacementPlugin()
],
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
host: process.env.HOST,
port: process.env.PORT,
stats: 'errors-only'
},
});
}
if(TARGET === 'build') {
module.exports = merge(common, {
entry: {
app: PATHS.app,
vendors: ['react']
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js'
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css'),
include: PATHS.css
}
]
},
plugins: [
new CleanPlugin([PATHS.build]),
new ExtractTextPlugin('styles.[chunkhash].css'),
new webpack.DefinePlugin({
// This has effect on the react lib size
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendors', 'manifest']
})
]
});
}