This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 510
/
makeconfig.js
126 lines (118 loc) · 3.6 KB
/
makeconfig.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
116
117
118
119
120
121
122
123
124
125
126
/* @flow weak */
'use strict';
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var NotifyPlugin = require('./notifyplugin');
var path = require('path');
var webpack = require('webpack');
var loaders = {
'css': '',
'less': '!less-loader',
'scss|sass': '!sass-loader',
'styl': '!stylus-loader'
};
module.exports = function(isDevelopment) {
function stylesLoaders() {
return Object.keys(loaders).map(function(ext) {
var prefix = 'css-loader!autoprefixer-loader?browsers=last 2 version';
var extLoaders = prefix + loaders[ext];
var loader = isDevelopment
? 'style-loader!' + extLoaders
: ExtractTextPlugin.extract('style-loader', extLoaders);
return {
loader: loader,
test: new RegExp('\\.(' + ext + ')$')
};
});
}
var config = {
cache: isDevelopment,
debug: isDevelopment,
devtool: isDevelopment ? 'eval-source-map' : '',
entry: {
app: isDevelopment ? [
'webpack-dev-server/client?http://localhost:8888',
// Why only-dev-server instead of dev-server:
// https://github.com/webpack/webpack/issues/418#issuecomment-54288041
'webpack/hot/only-dev-server',
'./src/client/main.js'
] : [
'./src/client/main.js'
],
// For Safari, IE<11, and some old browsers. More languages will need more
// specific builds.
appintl: isDevelopment ? [
'webpack-dev-server/client?http://localhost:8888',
// Why only-dev-server instead of dev-server:
// https://github.com/webpack/webpack/issues/418#issuecomment-54288041
'webpack/hot/only-dev-server',
'./node_modules/intl/Intl.js',
'./node_modules/intl/locale-data/jsonp/en.js',
'./src/client/main.js'
] : [
'./node_modules/intl/Intl.js',
'./node_modules/intl/locale-data/jsonp/en.js',
'./src/client/main.js'
]
},
module: {
loaders: [{
loader: 'url-loader?limit=100000',
test: /\.(gif|jpg|png|woff|woff2|eot|ttf|svg)$/
}, {
exclude: /node_modules/,
loaders: isDevelopment ? [
'react-hot', 'babel-loader'
] : [
'babel-loader'
],
test: /\.js$/
}].concat(stylesLoaders())
},
output: isDevelopment ? {
path: path.join(__dirname, '/build/'),
filename: '[name].js',
publicPath: 'http://localhost:8888/build/'
} : {
path: 'build/',
filename: '[name].js'
},
plugins: (function() {
var plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isDevelopment ? 'development' : 'production'),
IS_BROWSER: true
}
})
];
if (isDevelopment)
plugins.push(
NotifyPlugin,
new webpack.HotModuleReplacementPlugin(),
// Tell reloader to not reload if there is an error.
new webpack.NoErrorsPlugin()
);
else
plugins.push(
// Render styles into separate cacheable file to prevent FOUC and
// optimize for critical rendering path.
new ExtractTextPlugin('app.css', {
allChunks: true
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
// Because uglify reports so many irrelevant warnings.
warnings: false
}
})
);
return plugins;
})(),
resolve: {
extensions: ['', '.js', '.json']
}
};
return config;
};