-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.common.config.js
112 lines (103 loc) · 2.99 KB
/
webpack.common.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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const workboxPlugin = require('workbox-webpack-plugin');
const dotEnv = require('dotenv');
dotEnv.config();
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './client/index.html',
filename: 'index.html',
inject: 'body',
minify: {
html5: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
});
const DefinePluginConfig = new webpack.DefinePlugin({
GOOGLE_CLIENT_ID: JSON.stringify(process.env.GOOGLE_CLIENT_ID),
CLOUDINARY_API_BASE: JSON.stringify(process.env.CLOUDINARY_API_BASE),
CLOUDINARY_UPLOAD_PRESET: JSON.stringify(process.env
.CLOUDINARY_UPLOAD_PRESET),
CLOUDINARY_IMG_URL_STUB: JSON.stringify(process.env.CLOUDINARY_IMG_URL_STUB),
BOOK_IMAGE_FALLBACK: JSON.stringify(process.env.BOOK_IMAGE_FALLBACK),
BOOK_FALLBACK: JSON.stringify(process.env.BOOK_FALLBACK),
});
const ExtractTextConfig = new ExtractTextPlugin({ filename: 'style.css' });
const CommonsChunkPlugin = new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'common.js',
minChunks: 2,
});
const WorkBoxConfig = new workboxPlugin({
globDirectory: 'dist',
globPatterns: ['./client/**/*'],
swDest: path.join('dist', 'client/sw.js'),
swSrc: './client/sw.js',
});
const CopyPlugin = new CopyWebpackPlugin([
{ from: require.resolve('workbox-sw'), to: 'workbox-sw.prod.js' }
]);
module.exports = {
entry: {
app: path.resolve(__dirname, 'client/index.js'),
vendor: ['react', 'react-dom', 'react-router'],
pdf: ['react-pdf-js']
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist/client'),
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: ['node_modules', 'server', 'test', '__tests__', 'dist'],
loader: 'babel-loader',
query: {
presets: ['stage-2', 'react', 'env'],
plugins: ['transform-class-properties']
},
},
{
test: /\.(s*)css$/,
exclude: ['node_modules', 'dist'],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: { sourceMap: true, minimize: true }
},
{
loader: 'sass-loader',
options: { sourceMap: true },
}],
})
},
{
test: /\.(woff|png|jpg|gif)$/,
loader: 'url-loader?limit=250000'
}
]
},
plugins: [
HtmlWebpackPluginConfig,
CommonsChunkPlugin,
ExtractTextConfig,
DefinePluginConfig,
CopyPlugin,
WorkBoxConfig
]
};