-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathwebpack.config.js
172 lines (160 loc) · 4.35 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
171
172
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const NpmInstallPlugin = require('npm-install-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const AsyncAwaitPlugin = require('webpack-async-await') ;
const pkg = require('./package.json');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist'),
style: path.join(__dirname, 'src/main.css'),
};
const common = {
entry: {
src: PATHS.src,
style: PATHS.style,
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
module: {
preLoaders: [
{ test: /\.json$/, loader: 'json'},
],
loaders: [
{
test: /\.(jpg|png)$/,
loader: 'file?name=[path][name].[hash].[ext]',
// include: PATHS.images,
},
{
'test': /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?/,
loader: 'url',
query: {
prefix: 'font/',
limit: 10000,
mimetype: 'application/font-woff',
},
// include: PATHS.fonts,
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?/,
loader: 'url',
// include: PATHS.fonts,
},
],
},
output: {
path: PATHS.dist,
filename: '[name].js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Ethereum Transaction Building Demo',
}),
new AsyncAwaitPlugin(),
],
};
// Default Config
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: PATHS.dist,
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: process.env.HOST,
port: process.env.PORT,
},
module: {
loaders: [
// Define dev-specific CSS setup
{
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.src,
},
{
test: /\.jsx?$/,
loader: 'babel',
query: {
cacheDirectory: true,
presets: ['react', 'es2015', 'stage-1','react-hmre'],
plugins: ['transform-decorators-legacy', 'transform-object-assign', 'array-includes'],
},
include: PATHS.src,
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new NpmInstallPlugin({
save: true,
}),
],
});
}
if (TARGET === 'build') {
module.exports = merge(common, {
// devtool: 'source-map',
entry: {
// flag all `package.json` dependencies as vendor files
vendor: Object.keys(pkg.dependencies),
},
output: {
path: PATHS.build,
// filename: '[name].js',
// Create a hash for each file in the build so we can detect which files have changed
filename: '[name].[chunkhash].js',
chunkFilename: '[chunkhash].js',
},
module: {
loaders: [
// Extract CSS during the build process
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css'),
include: PATHS.src,
},
{
test: /\.jsx?$/,
loader: 'babel',
query: {
cacheDirectory: true,
presets: ['react', 'es2015', 'stage-1'],
plugins: ['transform-decorators-legacy', 'transform-object-assign', 'array-includes'],
},
include: PATHS.src,
},
],
},
plugins: [
// Clear the contents of the build directory before re-building
new CleanWebpackPlugin(PATHS.dist),
// Output extracted CSS to its own file
// new ExtractTextPlugin('[name].css'),
new ExtractTextPlugin('[name].[chunkhash].css'),
// Split dependencies into a `vendor` file and provide a manifest
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
}),
// Use the `production` flag so we get full optimization from React when building
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
// Minify the resulting bundle
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
],
});
}