-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
170 lines (158 loc) · 4.19 KB
/
webpack.config.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
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Clean = require('clean-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
test: path.join(__dirname, 'tests'),
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: PATHS.app,
resolve: {
extensions: ['', '.js', '.jsx'],
alias: {
'webworkify': 'webworkify-webpack',
},
},
output: {
path: PATHS.build,
// Output using entry name
filename: '[name].js',
},
node: {
fs: 'empty',
},
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css'],
},
{
test: /\.jsx?$/,
loaders: ['transform/cacheable?brfs', 'babel?cacheDirectory'],
include: [PATHS.app, path.resolve('node_modules/mapbox-gl-shaders/index.js')],
},
{
test: /\.json$/,
loader: 'json-loader',
},
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file' },
{ test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' },
],
postLoaders: [{
include: /node_modules\/mapbox-gl-shaders/,
loader: 'transform',
query: 'brfs',
}],
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.ejs',
title: 'Project Surat 👯',
appMountId: 'app',
inject: false,
}),
],
};
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'source-map',
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
// display only errors to reduce the amount of output
stats: 'errors-only',
// parse host and port from env so this is easy
// to customize
host: process.env.HOST,
port: process.env.PORT,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
});
}
if (TARGET === 'build') {
module.exports = merge(common, {
// Define entry points needed for splitting
entry: {
app: PATHS.app,
// vendor: Object.keys(pkg.dependencies).filter(v => v !== 'alt-utils'),
// Exclude alt-utils as it won't work with this setup
// due to the way the package has been designed
// (no package.json main).
},
output: {
path: PATHS.build,
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js',
},
plugins: [
new Clean([PATHS.build], {
verbose: true, // Don't write logs to console
}),
// Extract vendor and manifest files
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
}),
// Setting DefinePlugin affects React library size!
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
// You can set this to JSON.stringify('development') for your
// development target to force NODE_ENV to development mode
// no matter what
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
// minimize: true,
},
}),
// Webpack 2 configuration
// new webpack.LoaderOptionsPlugin({
// minimize: true,
// debug: false,
// }),
],
});
}
if (TARGET === 'test' || TARGET === 'tdd') {
module.exports = merge(common, {
devtool: 'inline-source-map',
resolve: {
alias: {
app: PATHS.app,
},
},
module: {
preLoaders: [
{
test: /\.jsx?$/,
loaders: ['isparta-instrumenter'],
include: PATHS.app,
},
],
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: PATHS.test,
},
],
},
externals: {
'cheerio': 'window',
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
});
}