generated from render-examples/wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
190 lines (184 loc) · 6.02 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
'use strict';
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const AssetsPlugin = require('assets-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const fs = require('fs');
// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
function resolveApp(relativePath) {
return path.resolve(appDirectory, relativePath);
}
const paths = {
appSrc: resolveApp('src'),
appBuild: resolveApp('build'),
appIndexJs: resolveApp('src/index.js'),
appNodeModules: resolveApp('node_modules'),
};
const DEV = process.env.NODE_ENV === 'development';
module.exports = {
bail: !DEV,
mode: DEV ? 'development' : 'production',
// We generate sourcemaps in production. This is slow but gives good results.
// You can exclude the *.map files from the build during deployment.
target: 'web',
devtool: DEV ? 'cheap-eval-source-map' : 'source-map',
entry: {
main: paths.appIndexJs,
// legacy: paths.appIndexLegacyJs,
},
output: {
path: paths.appBuild,
filename: DEV ? 'bundle.[name].js' : 'bundle.[name].[hash:8].js',
},
module: {
rules: [
// Disable require.ensure as it's not a standard language feature.
{ parser: { requireEnsure: false } },
// Transform ES6 with Babel
{
test: /\.js?$/,
loader: 'babel-loader',
include: paths.appSrc,
},
{
test: /\.(ttf|eot|svg|png|jpg|woff|woff2|gif|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
// back to the "file" loader at the end of the loader list.
oneOf: [
{
test: /.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: loader => [
require('postcss-import')({ root: loader.resourcePath }),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
}),
// Adds PostCSS Normalize as the reset css with default options,
// so that it honors browserslist config in package.json
// which in turn let's users customize the target behavior as per their needs.
require('postcss-normalize')(),
],
options: { sourceMap: !DEV },
},
},
{ loader: 'sass-loader' },
],
},
{
test: /.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: loader => [
require('postcss-import')({ root: loader.resourcePath }),
require('tailwindcss')('./tailwind.config.js'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
}),
// Adds PostCSS Normalize as the reset css with default options,
// so that it honors browserslist config in package.json
// which in turn let's users customize the target behavior as per their needs.
require('postcss-normalize')(),
],
options: { sourceMap: !DEV },
},
},
],
},
],
},
],
},
optimization: {
minimize: !DEV,
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
map: {
inline: false,
annotation: true,
},
},
}),
new TerserPlugin({
terserOptions: {
compress: {
warnings: false,
},
output: {
comments: false,
},
},
sourceMap: true,
}),
],
},
plugins: [
!DEV && new CleanWebpackPlugin(['build']),
// new CopyWebpackPlugin([
// {
// from: 'img',
// to: 'img',
// },
// ]),
new MiniCssExtractPlugin({
filename: DEV ? 'bundle.[name].css' : 'bundle.[name].[hash:8].css',
}),
new webpack.EnvironmentPlugin({
NODE_ENV: DEV ? 'development' : 'production', // use 'development' unless process.env.NODE_ENV is defined
DEBUG: false,
}),
new AssetsPlugin({
path: paths.appBuild,
filename: 'assets.json',
}),
DEV &&
new FriendlyErrorsPlugin({
clearConsole: false,
}),
DEV &&
new BrowserSyncPlugin({
notify: false,
host: 'localhost',
port: 5000,
logLevel: 'silent',
files: ['./**/*.php'],
proxy: 'http://localhost:9009/',
}),
].filter(Boolean),
};