-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.babel.js
165 lines (156 loc) · 3.63 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
import * as path from 'path';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CleanWebpackPlugin from 'clean-webpack-plugin';
import merge from 'webpack-merge';
const pkg = require('./package.json');
const TARGET = process.env.npm_lifecycle_event || '';
const ROOT_PATH = __dirname;
const config = {
paths: {
readme: path.join(ROOT_PATH, 'README.md'),
dist: path.join(ROOT_PATH, 'dist'),
src: path.join(ROOT_PATH, 'src'),
docs: path.join(ROOT_PATH, 'docs')
}
};
process.env.BABEL_ENV = TARGET;
const common = {
resolve: {
extensions: ['', '.js', '.jsx', '.css', '.png', '.jpg']
},
module: {
loaders: [
{
test: /\.md$/,
loaders: ['catalog/lib/loader', 'raw']
},
{
test: /\.png$/,
loader: 'url?limit=100000&mimetype=image/png',
include: config.paths.docs
},
{
test: /\.jpg$/,
loader: 'file',
include: config.paths.docs
},
{
test: /\.json$/,
loader: 'json',
include: path.join(ROOT_PATH, 'package.json')
}
]
}
};
const siteCommon = {
plugins: [
new HtmlWebpackPlugin({
template: require('html-webpack-template'), // eslint-disable-line global-require
inject: false,
mobile: true,
title: pkg.name,
appMountId: 'app'
}),
new webpack.DefinePlugin({
NAME: JSON.stringify(pkg.name),
USER: JSON.stringify(pkg.user),
VERSION: JSON.stringify(pkg.version)
})
]
};
if (TARGET === 'start') {
module.exports = merge(common, siteCommon, {
devtool: 'eval-source-map',
entry: {
docs: [config.paths.docs]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css']
},
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: [
config.paths.docs,
config.paths.src
]
}
]
},
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
host: process.env.HOST,
port: process.env.PORT,
stats: 'errors-only'
}
});
}
if (TARGET === 'gh-pages:build' || TARGET === 'gh-pages:stats') {
module.exports = merge(common, siteCommon, {
entry: {
app: config.paths.docs,
vendors: [
'react',
'react-dom'
]
},
output: {
path: './gh-pages',
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js'
},
plugins: [
new CleanWebpackPlugin(['gh-pages'], {
verbose: false
}),
new ExtractTextPlugin('[name].[chunkhash].css'),
new webpack.DefinePlugin({
// This affects the react lib size
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.CommonsChunkPlugin(
'vendor',
'[name].[chunkhash].js'
)
],
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css')
},
{
test: /\.jsx?$/,
loaders: ['babel'],
include: [
config.paths.docs,
config.paths.src
]
}
]
}
});
}
if (!TARGET) {
module.exports = common;
}