-
Notifications
You must be signed in to change notification settings - Fork 142
/
webpack.config.babel.js
181 lines (169 loc) · 4.1 KB
/
webpack.config.babel.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import * as fs from 'fs';
import * as path from 'path';
import fromPairs from 'lodash/fromPairs';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CleanWebpackPlugin from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import merge from 'webpack-merge';
const pkg = require('./lerna.json');
const ROOT_PATH = path.resolve(__dirname);
const config = {
paths: {
indexTemplate: path.join(ROOT_PATH, 'templates', 'index.ejs'),
build: path.join(ROOT_PATH, 'build'),
dist: path.join(ROOT_PATH, 'dist'),
src: path.join(ROOT_PATH, 'packages'),
ghPages: path.join(ROOT_PATH, 'gh-pages'),
documentation: path.join(ROOT_PATH, 'docs'),
'js-yaml': path.join(ROOT_PATH, 'node_modules', 'js-yaml')
}
};
const packages = fromPairs(fs.readdirSync('packages').map(p => [
p, path.join(config.paths.src, p, 'src')
]));
const common = {
entry: ['babel-polyfill', config.paths.documentation],
resolve: {
extensions: ['.js', '.jsx', '.md', '.css', '.png', '.jpg'],
alias: {
'js-yaml/dist/js-yaml.min.js': config.paths['js-yaml'],
'js-yaml': config.paths['js-yaml'],
// Reactabular aliases so that documentation and tests work
...packages
}
},
output: {
path: config.paths.build,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.md$/,
loaders: ['catalog/loader', 'raw-loader']
},
{
test: /\.png$/,
loaders: ['url-loader?limit=100000&mimetype=image/png'],
include: config.paths.documentation
},
{
test: /\.jpg$/,
loaders: ['file-loader'],
include: config.paths.documentation
},
{
test: /\.(js|jsx)$/,
loaders: ['babel-loader'],
include: [
config.paths.src,
config.paths.documentation
],
exclude: /node_modules/
}
]
}
};
const commonSite = {
devtool: 'source-map',
plugins: [
new HtmlWebpackPlugin({
template: config.paths.indexTemplate,
inject: false,
mobile: true,
title: pkg.name,
appMountId: 'app'
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version)
})
]
};
const developConfig = {
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
noInfo: true,
stats: 'errors-only'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style-loader', 'css-loader']
}
]
}
};
const ghPagesConfig = {
output: {
path: config.paths.ghPages,
filename: 'js/bundle.[chunkhash].js'
},
plugins: [
new CleanWebpackPlugin(['gh-pages']),
new CopyWebpackPlugin([{
from: './images',
to: './images'
}, {
from: './CNAME',
to: './'
}, {
from: './favicon.ico',
to: './'
}]),
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('production')
}
}),
new ExtractTextPlugin('[name].[chunkhash].css'),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module => /babel-standalone|js-yaml/.test(module.resource)
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
})
],
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},
{
test: /\.(js|jsx)$/,
loaders: ['babel-loader'],
include: config.paths.documentation
}
]
}
};
module.exports = (env) => {
process.env.BABEL_ENV = env;
if (env === 'develop') {
return merge(common, commonSite, developConfig);
}
if (env === 'build') {
return merge(common, commonSite, ghPagesConfig);
}
return common;
};