forked from jaredpalmer/presspack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
133 lines (127 loc) · 3.63 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
'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 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: [paths.appIndexJs],
output: {
path: paths.appBuild,
filename: DEV ? 'bundle.js' : 'bundle.[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: /.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
},
{
loader: "postcss-loader",
options: {
ident: "postcss", // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
autoprefixer({
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9" // React doesn't support IE8 anyway
]
})
]
}
},
"sass-loader"
],
}
],
},
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 MiniCssExtractPlugin({
filename: DEV ? 'bundle.css' : 'bundle.[hash:8].css'
}),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development', // 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: 4000,
logLevel: 'silent',
files: ['./template/*.php'],
proxy: 'http://localhost:9009/',
}),
].filter(Boolean),
};