forked from reactabular/reactabular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
190 lines (181 loc) · 4.71 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
182
183
184
185
186
187
188
189
190
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 catalogPkg = require('./node_modules/catalog/package.json');
const pkg = require('./lerna.json');
const TARGET = process.env.npm_lifecycle_event || '';
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')
]));
if (!process.env.BABEL_ENV) {
process.env.BABEL_ENV = TARGET;
}
const common = {
entry: 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/lib/loader', 'raw']
},
{
test: /\.png$/,
loaders: ['url?limit=100000&mimetype=image/png'],
include: config.paths.documentation
},
{
test: /\.jpg$/,
loaders: ['file'],
include: config.paths.documentation
},
{
test: /\.jsx?$/,
loaders: ['babel'],
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)
})
]
};
if (TARGET === 'start') {
module.exports = merge(common, commonSite, {
entry: config.paths.documentation,
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
noInfo: true,
stats: 'errors-only'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css']
},
{
test: require.resolve('react'),
loader: 'expose?React'
}
]
}
});
}
if (TARGET.startsWith('gh-pages')) {
module.exports = merge(common, commonSite, {
entry: {
app: config.paths.documentation,
vendor: Object.keys(catalogPkg.dependencies).concat([
'schema2object', 'lodash', 'react', 'react-dom',
'react-dnd', 'react-dnd-html5-backend',
'react-github-corner', 'react-redux', 'redux', 'uuid',
'annogenerate', 'selectabular', 'deep-diff',
'searchtabular', 'sortabular', 'treetabular',
'react-edit', 'table-resolver', 'react-visibility-toggles'
])
},
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.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
filename: 'js/[name].[chunkhash].js'
})
],
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css')
},
{
test: /\.jsx?$/,
loaders: ['babel'],
include: config.paths.documentation
}
]
}
});
}
if (!TARGET) {
module.exports = common;
}