-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
101 lines (93 loc) · 2.4 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
const webpack = require('webpack');
const path = require('path');
const cssnext = require('postcss-cssnext');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BUILD_DIR = path.resolve(__dirname, 'dist');
const APP_DIR = path.resolve(__dirname, 'app');
const NODE_MODULES = path.resolve(__dirname, 'node_modules');
const plugins = [
new ExtractTextPlugin('[name].css'),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'index.html'),
filename: 'index.html',
inject: true
}),
new webpack.NoErrorsPlugin(),
new CopyWebpackPlugin([
{ from: 'css', to: 'css' }
])
];
function getJenkinsBuildInformation() {
return {
timeStamp: new Date().toISOString(),
revision: process.env.GIT_COMMIT || 'HEAD',
branch: process.env.GIT_BRANCH || 'develop',
jenkinsTag: process.env.BUILD_TAG || 'local',
jenkinsUrl: process.env.BUILD_URL || undefined,
version: require('./package.json').version
};
}
const release = process.env.NODE_ENV === 'production';
if (release) {
plugins.push(new webpack.DefinePlugin({
'process.env': JSON.stringify({
debug: false,
NODE_ENV: 'production',
REST_API_URL: process.env.REST_API_URL,
})
}));
plugins.push(new webpack.optimize.DedupePlugin());
plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
mangle: false,
compress: {
warnings: false
}
}));
} else {
plugins.push(new webpack.DefinePlugin({
'process.env': JSON.stringify({
debug: true,
NODE_ENV: 'development',
REST_API_URL: process.env.REST_API_URL,
buildRevisionInfo: getJenkinsBuildInformation()
})
}));
}
const config = {
debug: !release,
devtool: 'source-map',
entry: [
'babel-polyfill',
path.join(APP_DIR, 'index')
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loaders: ['babel'],
exclude: NODE_MODULES
},
{
test: /\.css$/,
loader: 'style-loader!css-loader?modules&importLoaders=1!postcss-loader',
exclude: NODE_MODULES
}
]
},
output: {
path: BUILD_DIR,
filename: '[name].js',
publicPath: '/'
},
plugins: plugins,
postcss: function () {
return [cssnext];
},
resolve: {
extensions: ['', '.js', '.jsx']
}
};
module.exports = config;