-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.common.js
More file actions
175 lines (169 loc) · 5.22 KB
/
webpack.common.js
File metadata and controls
175 lines (169 loc) · 5.22 KB
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
const path = require('path');
const webpack = require('webpack');
const bootstrapEntryPoints = require('./webpack.bootstrap.config');
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Visualizer = require('webpack-visualizer-plugin');
const isProd = process.env.NODE_ENV === 'production';
const bootstrapConfig = isProd ? bootstrapEntryPoints.prod : bootstrapEntryPoints.dev;
module.exports = {
entry: {
// According to HtmlWebpackPlugin config, it's possible that
// not all entry chunks are included into index.html
main: [
'react-hot-loader/patch',
'./src/index.js'
],
/*
** A bootstrap entry is added. To Use bootstrap class styles, simply add
** 'bootstrap' to HtmlWebpackPlugin chunks array. Bootstrap scripts are
** disabled by default, which can be enabled selectively by tweaking .bootstraprc.
*/
bootstrap: bootstrapConfig
},
resolve: {
// Tell webpack what directories should be searched when resolving modules.
modules: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "assets"),
"node_modules"
]
},
plugins: [
new HtmlWebpackPlugin({
template: './index-template.html',
// manifest should be included before main,
// but html webpack plugin will take care of this.
chunks: ['main', 'manifest', /*'bootstrap'*/], // select the entry items to include
}),
new webpack.ProvidePlugin({
"window.Tether": "tether"
}),
new webpack.ProvidePlugin({
React: 'react',
Component: ['react', 'Component'],
// For Bootstrap
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Tether: "tether",
"window.Tether": "tether",
Alert: "exports-loader?Alert!bootstrap/js/dist/alert",
Button: "exports-loader?Button!bootstrap/js/dist/button",
Carousel: "exports-loader?Carousel!bootstrap/js/dist/carousel",
Collapse: "exports-loader?Collapse!bootstrap/js/dist/collapse",
Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
Modal: "exports-loader?Modal!bootstrap/js/dist/modal",
Popover: "exports-loader?Popover!bootstrap/js/dist/popover",
Scrollspy: "exports-loader?Scrollspy!bootstrap/js/dist/scrollspy",
Tab: "exports-loader?Tab!bootstrap/js/dist/tab",
Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
Util: "exports-loader?Util!bootstrap/js/dist/util",
}),
new CleanWebpackPlugin(['dist']),
new webpack.DllReferencePlugin({
context: path.join(__dirname),
manifest: require('./build/vendor-manifest.json'),
}),
// A lesser-known feature of the CommonsChunkPlugin is extracting
// webpack's boilerplate and manifest which can change with every build.
// By specifying a name not mentioned in the entry configuration,
// the plugin will automatically extract what we want into a separate bundle
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
new AddAssetHtmlPlugin({
includeSourcemap: true,
hash: true,
filepath: require.resolve('./build/vendor.dll.js')
}),
new Visualizer()
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
chunkFilename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
loaders: [
{
loader: 'url-loader',
options: {
limit: 8192,
name: 'images/[hash:12].[ext]'
}
},
{
loader: 'image-webpack-loader',
options: {
gifsicle: {
interlaced: false
},
optipng: {
optimizationLevel: 7
},
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true,
quality: 65
},
// Specifying webp here will create a WEBP version of your JPG/PNG images
webp: {
quality: 75
}
}
}
]
},
{
test: /\.(woff2)$/,
loaders: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: 'fonts/[name].[ext]'
}
}
]
},
{
test: /\.(ttf|eot|otf|woff)$/,
use: [
'file-loader?name=fonts/[name].[ext]'
]
},
{
test: /\.(csv|tsv)$/,
use: [
'csv-loader'
]
},
{
test: /\.xml$/,
use: [
'xml-loader'
]
},
// Use one of these to serve jQuery for Bootstrap scripts:
// Bootstrap 4
{ test: /bootstrap\/dist\/js\/umd\//, use: 'imports-loader?jQuery=jquery' },
// Bootstrap 3
{ test: /bootstrap-sass\/assets\/javascripts\//, use: 'imports-loader?jQuery=jquery' },
]
}
};