forked from henroben/wordpress-react-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (110 loc) · 3.75 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
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const VENDOR_LIBS = [
'lodash',
'moment',
'react',
'react-dom',
'react-redux',
'react-router',
'redux',
'redux-thunk'
];
module.exports = {
entry: {
bundle: ['./src/index.js', './style/style.scss', 'bootstrap-loader/extractStyles'],
vendor: VENDOR_LIBS
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[chunkhash].js', // replaces [name] with key from entry section
publicPath: '/'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/ // exclude node modules as trust that all are ES5 already
},
{ // sass / scss loader for webpack
test: /\.(sass|scss)$/,
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader'])
},
{
test: /\.(jpe?g|png|gif|svg)$/, // set file types to handle
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
publicPath: '../',
name: 'img/[hash].[ext]' }
}, // depending on image size, will either incorporate img directly into bundle.js (< 40 kb) or supply link, use object rather than string so can set config
{
loader: 'image-webpack-loader',
query: {
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
},
pngquant: {
quality: '65-90',
speed: 4
}
}
} // first to be applied
]
},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
// Limiting the size of the woff fonts breaks font-awesome ONLY for the extract text plugin
// loader: "url?limit=10000"
// use: "url-loader?name=fonts/[name].[ext]"
use: [
{
loader: 'url-loader',
options: { publicPath: '../', name:'./fonts/[name].[ext]'}
}
]
},
{
test: /\.(ttf|eot)(\?[\s\S]+)?$/,
use: 'file-loader?name=fonts/[name].[ext]'
},
{
test: /\.min\.css$/,
use: 'file-loader?name=css/[name].[ext]'
}
]
},
devServer: {
historyApiFallback: true,
contentBase: './',
port: 3030
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}), // checks double including between bundle & vendor, any duplicates are only added to vendor.js
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new ExtractTextPlugin({
filename: 'css/style.[chunkhash].css',
allChunks: true,
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development')
}
})
]
};