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 513
/
makeconfig.js
141 lines (132 loc) · 4.42 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* @flow weak */
'use strict';
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var NotifyPlugin = require('./notifyplugin');
var constants = require('./constants');
var path = require('path');
var webpack = require('webpack');
var devtools = process.env.CONTINUOUS_INTEGRATION
? 'inline-source-map'
// cheap-module-eval-source-map, because we want original source, but we don't
// care about columns, which makes this devtool faster than eval-source-map.
// http://webpack.github.io/docs/configuration.html#devtool
: 'cheap-module-eval-source-map';
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 ? devtools : '',
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',
path.join(constants.SRC_DIR, 'client/main.js')
] : [
path.join(constants.SRC_DIR, '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',
path.join(constants.NODE_MODULES_DIR, 'intl/Intl.js'),
path.join(constants.NODE_MODULES_DIR, 'intl/locale-data/jsonp/en.js'),
path.join(constants.SRC_DIR, 'client/main.js')
] : [
path.join(constants.NODE_MODULES_DIR, 'intl/Intl.js'),
path.join(constants.NODE_MODULES_DIR, 'intl/locale-data/jsonp/en.js'),
path.join(constants.SRC_DIR, '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: constants.BUILD_DIR,
filename: '[name].js',
chunkFilename: '[name]-[chunkhash].js',
publicPath: 'http://localhost:8888/build/'
} : {
path: constants.BUILD_DIR,
filename: '[name].js',
chunkFilename: '[name]-[chunkhash].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'],
modulesDirectories: ['src', 'node_modules'],
root: constants.ABSOLUTE_BASE,
alias: {
'react$': require.resolve(path.join(constants.NODE_MODULES_DIR, 'react'))
}
}
};
return config;
};