-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
179 lines (171 loc) · 4.84 KB
/
Copy pathwebpack.prod.js
File metadata and controls
179 lines (171 loc) · 4.84 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
176
177
178
179
/* eslint-disable no-undef */
var path = require('path');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var autoprefixer = require('autoprefixer');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
var webpack = require('webpack');
var CopyPlugin = require('copy-webpack-plugin');
var ImageminPlugin = require('imagemin-webpack-plugin').default;
var ProcessAfterBuild = require('./critical-css-postprocessor');
// Resolved rather than assumed at ./node_modules, so the copy below works in a
// worktree with a symlinked node_modules as well as in a plain checkout. The
// package's exports map only exposes the unminified builds, so the directory is
// resolved through the main entry and the minified filenames joined onto it.
const photoswipeDist = path.dirname(require.resolve('photoswipe'));
const sourceDir = __dirname + '/static/';
const outputPath = __dirname + '/static/COMPILED/';
const newStyleRule = {
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: false,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [autoprefixer()],
},
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
};
var plugins = [
new MiniCssExtractPlugin({
filename: 'assets/css/[name].css',
ignoreOrder: false,
}),
new CopyPlugin({
patterns: [
{
from: './static/img/*.*',
to: 'assets/img/[name][ext]',
},
{
from: './static/img/screenshots',
to: 'assets/img/screenshots',
},
// PhotoSwipe is loaded as ES modules by the gallery, so it is copied
// rather than bundled. It used to come from a CDN, unpinned. Only the
// three files the gallery imports are taken: dist also ships UMD builds,
// type definitions and source maps.
{
from: path.join(photoswipeDist, 'photoswipe.esm.min.js'),
to: 'photoswipe/[name][ext]',
},
{
from: path.join(photoswipeDist, 'photoswipe-lightbox.esm.min.js'),
to: 'photoswipe/[name][ext]',
},
{
from: path.join(photoswipeDist, 'photoswipe.css'),
to: 'photoswipe/[name][ext]',
},
],
}),
new ImageminPlugin(
{
pngquant: ({ quality: '50' }),
jpegtran: ({ quality: '50' }),
},
),
new CleanWebpackPlugin(),
];
module.exports = (env, argv) => {
const isProductionMode = argv.mode === 'production';
// The critical css step drives a browser and takes most of the build's
// wall clock, so it is production only: a development build wants the whole
// stylesheet anyway. This used to be a bespoke --optimize=false flag, which
// webpack-cli 5 rejects outright as an unknown option, so nothing could pass
// it and a development build was not possible.
if (isProductionMode) {
plugins.push(new ProcessAfterBuild());
plugins.push(new webpack.SourceMapDevToolPlugin({
filename: '[file].map[query]',
exclude: ['vendor.js'],
}));
}
return {
context: __dirname,
mode: env.NODE_ENV,
entry: {
'webp': './static/js/webp.js',
'main': './static/js/index.js',
'styleguide': './pgaweb/static/css/styleguide.scss',
},
output: {
path: outputPath,
filename: '[name].js',
libraryExport: 'default',
},
devtool: false,
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
},
},
},
newStyleRule,
{
test: /\.(jpe?g|png|gif|svg)$/i,
include: [/node_modules/, path.join(sourceDir, '/assets/img')],
loader: 'file-loader',
options: {
name: 'assets/css/[name].[ext]',
limit: 10000,
},
},
{
test: /\.(woff|woff2|eot|ttf|otf|png)?$/,
include: [
/node_modules/,
path.join(sourceDir, '/assets/css/'),
path.join(sourceDir, '/assets/fonts/'),
],
loader: 'file-loader',
options: {
limit: 1000,
useRelativePath: true,
name: 'assets/css/[name].[ext]',
},
},
],
},
resolve: {
extensions: ['.js', '.css', '.less', '.json'],
modules: ['./node_modules'],
},
plugins: plugins,
performance: {
maxEntrypointSize: 1024000,
maxAssetSize: 1024000,
hints: 'warning',
},
stats: {
children: false,
assets: false,
warnings: false,
},
};
};