@ideasonpurpose/build-tools-wordpress 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +13 -11
- package/config/webpack.config.js +12 -10
- package/example/webpack.config.js +1 -617
- package/lib/WatchRunReporterPlugin.js +1 -1
- package/lib/buildConfig.js +33 -7
- package/package.json +14 -19
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### v1.2.1
|
|
8
|
+
|
|
9
|
+
> 19 September 2024
|
|
10
|
+
|
|
11
|
+
- plugins updates, config fixes
|
|
12
|
+
|
|
7
13
|
#### v1.2.0
|
|
8
14
|
|
|
9
15
|
> 19 September 2024
|
package/README.md
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
# @ideasonpurpose/build-tools-wordpress
|
|
2
2
|
|
|
3
|
-
#### Version
|
|
3
|
+
#### Version 2.0.0
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
|
|
6
6
|
[](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
|
|
7
7
|
|
|
8
8
|
Build scripts and dependencies for IOP's WordPress development environments.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## About This Package
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- **`src`** - The **source** directory containing source files which should be compiled or transposed. The contents of this directory will be omitted from builds.
|
|
15
|
-
- **`dist`** - The **distribution** directory where processed, production-ready files will be output to. All contents of this directory will be included in builds.
|
|
16
|
-
- **`src`** - An array of file entry points relative to the `src` directory. Each entry point will generate a like-named output file. All files and assets imported by a given entry point will be accessible from that entry's corresponding output file.
|
|
12
|
+
These tools were migrated from our [Docker-based WordPress build tools](https://github.com/ideasonpurpose/docker-build) to speed up development and began the process of moving our build tools away from webpack. Gathering dependencies also simplifies the package.json and configuration files in host projects, making those slightly more manageable.
|
|
17
13
|
|
|
18
14
|
### Versioned Releases
|
|
19
15
|
|
|
20
|
-
IOP versions our themes so every release creates a clear rollback snapshot. To accomplish this, every milestone build is generated into a versioned directory. This works well for themes where only one can be active, but fails for plugins where multiple versions can be simultaneously enabled so long as their directory names are different.
|
|
16
|
+
IOP versions our themes so every release creates a clear rollback snapshot. To accomplish this, every milestone build is generated into a versioned directory. This works well for themes where only one can be active, but fails for plugins where multiple versions can be simultaneously enabled so long as their directory names are different.
|
|
21
17
|
|
|
22
18
|
To work around this, a `type` property can be added to the config file. When `type` is `plugin`, builds will not add the version to directory names.
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
### Optional Config
|
|
21
|
+
|
|
22
|
+
Each project may optionally include an **ideasonpurpose.config.js** file in the same directory as **package.json**. Any settings in this file will override [the defaults](https://github.com/ideasonpurpose/build-tools-wordpress/blob/main/config/ideasonpurpose.config.js).
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
<!--
|
|
25
|
+
|
|
26
|
+
- **`src`** - The **source** directory containing source files which should be compiled or transposed. The contents of this directory will be omitted from builds.
|
|
27
|
+
- **`dist`** - The **distribution** directory where processed, production-ready files will be output to. All contents of this directory will be included in builds.
|
|
28
|
+
- **`src`** - An array of file entry points relative to the `src` directory. Each entry point will generate a like-named output file. All files and assets imported by a given entry point will be accessible from that entry's corresponding output file.
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
-->
|
|
29
31
|
|
|
30
32
|
### Additional Notes
|
|
31
33
|
|
package/config/webpack.config.js
CHANGED
|
@@ -66,10 +66,11 @@ const stats = {
|
|
|
66
66
|
groupAssetsByChunk: true,
|
|
67
67
|
entrypoints: true,
|
|
68
68
|
// // errorDetails: "auto",
|
|
69
|
+
errorDetails: false,
|
|
69
70
|
children: false,
|
|
70
71
|
// errorDetails: true,
|
|
71
72
|
errors: true,
|
|
72
|
-
errorStack:
|
|
73
|
+
errorStack: false,
|
|
73
74
|
// excludeAssets: [/hot-update/, /_sock-/],
|
|
74
75
|
// groupAssetsByChunk: true,
|
|
75
76
|
// logging: "warn",
|
|
@@ -252,15 +253,16 @@ export default async (env) => {
|
|
|
252
253
|
webpackImporter: false,
|
|
253
254
|
sassOptions: {
|
|
254
255
|
// api: "modern",
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
256
|
+
api: "modern-compiler",
|
|
257
|
+
|
|
258
|
+
// includePaths: [
|
|
259
|
+
// path.resolve(config.src, "sass"),
|
|
260
|
+
// path.resolve(config.src),
|
|
261
|
+
// // path.resolve("../site/node_modules"),
|
|
262
|
+
// path.resolve("node_modules"),
|
|
263
|
+
// ],
|
|
264
|
+
// style: "expanded",
|
|
265
|
+
// verbose: true,
|
|
264
266
|
},
|
|
265
267
|
},
|
|
266
268
|
},
|
|
@@ -1,617 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { statSync } from "fs";
|
|
4
|
-
import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
8
|
-
import { EsbuildPlugin } from "esbuild-loader";
|
|
9
|
-
|
|
10
|
-
import CopyPlugin from "copy-webpack-plugin";
|
|
11
|
-
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
12
|
-
import ImageMinimizerPlugin from "image-minimizer-webpack-plugin";
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
AfterDoneReporterPlugin,
|
|
16
|
-
buildConfig,
|
|
17
|
-
DependencyManifestPlugin,
|
|
18
|
-
devserverProxy,
|
|
19
|
-
findLocalPort,
|
|
20
|
-
WatchRunReporterPlugin,
|
|
21
|
-
} from "@ideasonpurpose/build-tools-wordpress";
|
|
22
|
-
|
|
23
|
-
import autoprefixer from "autoprefixer";
|
|
24
|
-
import cssnano from "cssnano";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sass flavors for conditional sass-loader implementations
|
|
28
|
-
*/
|
|
29
|
-
// import * as nodeSass from "sass";
|
|
30
|
-
// import * as dartSass from "sass-embedded";
|
|
31
|
-
|
|
32
|
-
// Experimenting with this
|
|
33
|
-
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Force `mode: production` when running the analyzer
|
|
37
|
-
* TODO: webpack5 changed env in here, might need to change WEBPACK_BUNDLE_ANALYZER
|
|
38
|
-
*/
|
|
39
|
-
if (process.env.WEBPACK_BUNDLE_ANALYZER) process.env.NODE_ENV = "production";
|
|
40
|
-
|
|
41
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
42
|
-
|
|
43
|
-
const stats = {
|
|
44
|
-
preset: "normal",
|
|
45
|
-
cachedAssets: false,
|
|
46
|
-
assets: true,
|
|
47
|
-
// assetsSpace: 12,
|
|
48
|
-
// context: new URL( import.meta.url).pathname,
|
|
49
|
-
// all: true,
|
|
50
|
-
// assets: true,
|
|
51
|
-
// builtAt: true,
|
|
52
|
-
// cachedModules: true,
|
|
53
|
-
// children: false, // Adds a bunch of blank lines to stats output
|
|
54
|
-
// chunkGroups: false,
|
|
55
|
-
// chunkModules: false,
|
|
56
|
-
// chunkOrigins: true,
|
|
57
|
-
// chunkRelations: true,
|
|
58
|
-
// chunks: false,
|
|
59
|
-
// colors: true,
|
|
60
|
-
// depth: false,
|
|
61
|
-
// env: true,
|
|
62
|
-
// orphanModules: false,
|
|
63
|
-
// dependentModules: true,
|
|
64
|
-
modules: false,
|
|
65
|
-
groupAssetsByChunk: true,
|
|
66
|
-
entrypoints: true,
|
|
67
|
-
// // errorDetails: "auto",
|
|
68
|
-
children: false,
|
|
69
|
-
// errorDetails: true,
|
|
70
|
-
errors: true,
|
|
71
|
-
errorStack: true,
|
|
72
|
-
// excludeAssets: [/hot-update/, /_sock-/],
|
|
73
|
-
// groupAssetsByChunk: true,
|
|
74
|
-
// logging: "warn",
|
|
75
|
-
// optimizationBailout: true,
|
|
76
|
-
// loggingTrace: false,
|
|
77
|
-
performance: true,
|
|
78
|
-
reasons: true,
|
|
79
|
-
relatedAssets: true,
|
|
80
|
-
timings: true,
|
|
81
|
-
version: true,
|
|
82
|
-
warnings: true,
|
|
83
|
-
loggingDebug: ["sass-loader"],
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default async (env) => {
|
|
87
|
-
const siteDir = new URL(import.meta.url).pathname;
|
|
88
|
-
const explorer = cosmiconfig("ideasonpurpose", { searchStrategy: "project" });
|
|
89
|
-
const configFile = await explorer.search(siteDir);
|
|
90
|
-
|
|
91
|
-
const config = await buildConfig(configFile);
|
|
92
|
-
|
|
93
|
-
const proxy = isProduction ? {} : await devserverProxy(config);
|
|
94
|
-
|
|
95
|
-
setTimeout(() =>
|
|
96
|
-
console.log(
|
|
97
|
-
chalk.magenta.bold("sass implementation"),
|
|
98
|
-
chalk.yellow.bold(config.sass),
|
|
99
|
-
// config.sass === "sass" ? nodeSass : dartSass,
|
|
100
|
-
),
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* `usePolling` is a placeholder, try and detect native Windows Docker mounts
|
|
105
|
-
* since they don't support file-watching (no inotify events), if there's
|
|
106
|
-
* something clean, use that instead. For now, this will force-enable polling.
|
|
107
|
-
*
|
|
108
|
-
* TODO: Why so much dancing around defaults when this could just inherit from default.config?
|
|
109
|
-
*/
|
|
110
|
-
const usePolling = Boolean(config.usePolling); // likely undefined, coerced to false
|
|
111
|
-
const pollInterval = Math.max(
|
|
112
|
-
parseInt(config.pollInterval, 10) || parseInt(config.usePolling, 10) || 400,
|
|
113
|
-
400,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const devtool = config.devtool || false;
|
|
117
|
-
|
|
118
|
-
const sassLibs = ["sass-embedded", "sass", "node-sass"];
|
|
119
|
-
const sassImplementation = sassLibs.includes(config.sass)
|
|
120
|
-
? { implementation: config.sass }
|
|
121
|
-
: {};
|
|
122
|
-
|
|
123
|
-
// TODO: Move this into buildConfig()
|
|
124
|
-
config.esTarget = config.esTarget || "es2020"; // was "es2015"
|
|
125
|
-
|
|
126
|
-
console.log({
|
|
127
|
-
metaurl: new URL("webpack/stats/index.html", import.meta.url),
|
|
128
|
-
config,
|
|
129
|
-
// devServerProxy: await devserverProxy(config),
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
// stats: "errors-warnings",
|
|
134
|
-
stats,
|
|
135
|
-
module: {
|
|
136
|
-
rules: [
|
|
137
|
-
// {
|
|
138
|
-
// test: /\.(js|jsx|mjs)$/,
|
|
139
|
-
// include: [
|
|
140
|
-
// path.resolve(config.src),
|
|
141
|
-
// path.resolve("../tools/node_modules"),
|
|
142
|
-
// path.resolve("../site/node_modules"),
|
|
143
|
-
// ],
|
|
144
|
-
// exclude: function (module) {
|
|
145
|
-
// const moduleRegex = new RegExp(
|
|
146
|
-
// `node_modules/(${config.transpileDependencies.join("|")})`
|
|
147
|
-
// );
|
|
148
|
-
// return /node_modules/.test(module) && !moduleRegex.test(module);
|
|
149
|
-
// },
|
|
150
|
-
|
|
151
|
-
// /**
|
|
152
|
-
// * EXPERIMENTAL!!
|
|
153
|
-
// * If JS compilation breaks, try reverting this first.
|
|
154
|
-
// */
|
|
155
|
-
// loader: "esbuild-loader",
|
|
156
|
-
// options: {
|
|
157
|
-
// loader: "jsx",
|
|
158
|
-
// target: "es2015",
|
|
159
|
-
// },
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Updated 2022-09, simpler
|
|
163
|
-
*/
|
|
164
|
-
{
|
|
165
|
-
test: /\.[jt]sx?$/,
|
|
166
|
-
// test: /\.js$/,
|
|
167
|
-
loader: "esbuild-loader",
|
|
168
|
-
options: {
|
|
169
|
-
loader: "jsx",
|
|
170
|
-
target: config.esTarget,
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
// {
|
|
174
|
-
// test: /\.tsx?$/,
|
|
175
|
-
// loader: "esbuild-loader",
|
|
176
|
-
// options: {
|
|
177
|
-
// loader: "tsx",
|
|
178
|
-
// target: config.esTarget,
|
|
179
|
-
// },
|
|
180
|
-
// },
|
|
181
|
-
|
|
182
|
-
// use: {
|
|
183
|
-
// loader: "babel-loader",
|
|
184
|
-
// options: {
|
|
185
|
-
// cacheDirectory: !isProduction,
|
|
186
|
-
// sourceType: "unambiguous",
|
|
187
|
-
// plugins: [
|
|
188
|
-
// "@babel/plugin-syntax-dynamic-import",
|
|
189
|
-
// ...(isProduction
|
|
190
|
-
// ? []
|
|
191
|
-
// : ["@babel/plugin-transform-react-jsx-source"]),
|
|
192
|
-
// ],
|
|
193
|
-
// presets: [
|
|
194
|
-
// [
|
|
195
|
-
// "@babel/preset-env",
|
|
196
|
-
// {
|
|
197
|
-
// forceAllTransforms: true,
|
|
198
|
-
// useBuiltIns: "usage",
|
|
199
|
-
// configPath: config.src,
|
|
200
|
-
// corejs: 3,
|
|
201
|
-
// modules: false,
|
|
202
|
-
// debug: false,
|
|
203
|
-
// },
|
|
204
|
-
// ],
|
|
205
|
-
// "@babel/preset-react",
|
|
206
|
-
// ],
|
|
207
|
-
// },
|
|
208
|
-
// },
|
|
209
|
-
// },
|
|
210
|
-
{
|
|
211
|
-
test: /\.(scss|css)$/,
|
|
212
|
-
use: [
|
|
213
|
-
{ loader: MiniCssExtractPlugin.loader },
|
|
214
|
-
{
|
|
215
|
-
loader: "css-loader",
|
|
216
|
-
options: {
|
|
217
|
-
import: false, // imports already handled by Sass or PostCSS
|
|
218
|
-
// sourceMap: !isProduction,
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
loader: "postcss-loader",
|
|
223
|
-
options: {
|
|
224
|
-
postcssOptions: {
|
|
225
|
-
plugins: isProduction
|
|
226
|
-
? [
|
|
227
|
-
autoprefixer,
|
|
228
|
-
cssnano({ preset: ["default", { colormin: false }] }),
|
|
229
|
-
]
|
|
230
|
-
: [autoprefixer],
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
// {
|
|
235
|
-
// loader: "resolve-url-loader",
|
|
236
|
-
// options: {
|
|
237
|
-
// // sourceMap: true,
|
|
238
|
-
// // debug: true,
|
|
239
|
-
// },
|
|
240
|
-
// },
|
|
241
|
-
{
|
|
242
|
-
loader: "sass-loader",
|
|
243
|
-
options: {
|
|
244
|
-
...sassImplementation,
|
|
245
|
-
// implementation: config.sass === "sass" ? nodeSass : dartSass,
|
|
246
|
-
// implementation: nodeSass,
|
|
247
|
-
// implementation: await import(config.sass),
|
|
248
|
-
sourceMap: !isProduction,
|
|
249
|
-
warnRuleAsWarning: true,
|
|
250
|
-
webpackImporter: false,
|
|
251
|
-
sassOptions: {
|
|
252
|
-
// api: "modern",
|
|
253
|
-
|
|
254
|
-
includePaths: [
|
|
255
|
-
path.resolve(config.src, "sass"),
|
|
256
|
-
path.resolve(config.src),
|
|
257
|
-
// path.resolve("../site/node_modules"),
|
|
258
|
-
path.resolve("node_modules"),
|
|
259
|
-
],
|
|
260
|
-
style: "expanded",
|
|
261
|
-
verbose: true,
|
|
262
|
-
},
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
},
|
|
267
|
-
/**
|
|
268
|
-
* This image loader is specifically for images which are required or
|
|
269
|
-
* imported into a webpack processed entry file. Optimization is
|
|
270
|
-
* handled by image-minimizer-webpack-plugin. These assets will be
|
|
271
|
-
* renamed with a chunkhash fragment.
|
|
272
|
-
*
|
|
273
|
-
* All images under `config.src` will be optimized and copied by
|
|
274
|
-
* copy-webpack-plugin but will keep their original filenames and
|
|
275
|
-
* relative paths. Images included in SCSS files will be processed
|
|
276
|
-
* twice, once with a hashed name and again with its original name.
|
|
277
|
-
*/
|
|
278
|
-
{
|
|
279
|
-
test: /\.(jpe?g|png|gif|tif|webp|avif)$/i,
|
|
280
|
-
type: "asset",
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* SVGs can be imported as asset urls or React components
|
|
285
|
-
*
|
|
286
|
-
* To import an SVG file as a src url, append ?url to the filename:
|
|
287
|
-
* import svg from './assets/file.svg?url'
|
|
288
|
-
*
|
|
289
|
-
* To import an SVG file as a React component
|
|
290
|
-
|
|
291
|
-
* @link https://react-svgr.com/docs/webpack/#use-svgr-and-asset-svg-in-the-same-project
|
|
292
|
-
*/
|
|
293
|
-
{
|
|
294
|
-
test: /\.svg$/i,
|
|
295
|
-
type: "asset",
|
|
296
|
-
resourceQuery: /url/, // *.svg?url
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
test: /\.svg$/i,
|
|
300
|
-
issuer: /\.[jt]sx?$/,
|
|
301
|
-
resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url
|
|
302
|
-
use: ["@svgr/webpack"],
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
test: /fonts\/.*\.(ttf|eot|woff2?)$/i,
|
|
306
|
-
type: "asset",
|
|
307
|
-
},
|
|
308
|
-
],
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
context: path.resolve(config.src),
|
|
312
|
-
|
|
313
|
-
resolve: {
|
|
314
|
-
modules: [
|
|
315
|
-
path.resolve("../tools/node_modules"),
|
|
316
|
-
path.resolve("../site/node_modules"),
|
|
317
|
-
path.resolve("./node_modules"),
|
|
318
|
-
],
|
|
319
|
-
},
|
|
320
|
-
|
|
321
|
-
resolveLoader: {
|
|
322
|
-
modules: [
|
|
323
|
-
path.resolve("../tools/node_modules"),
|
|
324
|
-
path.resolve("./node_modules"), // for local development when running outside of Docker
|
|
325
|
-
],
|
|
326
|
-
},
|
|
327
|
-
|
|
328
|
-
entry: config.entry,
|
|
329
|
-
|
|
330
|
-
output: {
|
|
331
|
-
path: new URL(config.dist, import.meta.url).pathname,
|
|
332
|
-
/**
|
|
333
|
-
* Primary output filenames SHOULD NOT include hashes in development because
|
|
334
|
-
* some files are written to disk from devServer middleware. Because those
|
|
335
|
-
* files are written outside standard webpack output, they aren't cleaned
|
|
336
|
-
* up by standard webpack cleaning functions.
|
|
337
|
-
*/
|
|
338
|
-
filename: isProduction ? "[name]-[contenthash:8].js" : "[name].js",
|
|
339
|
-
chunkFilename: "[id]-[chunkhash:8].js",
|
|
340
|
-
publicPath: config.publicPath,
|
|
341
|
-
/**
|
|
342
|
-
* Assets are not cleaned when writeToDisk is true in devServer
|
|
343
|
-
* Works correctly with builds.
|
|
344
|
-
* @link https://github.com/webpack/webpack-dev-middleware/issues/861
|
|
345
|
-
*/
|
|
346
|
-
clean: true,
|
|
347
|
-
},
|
|
348
|
-
|
|
349
|
-
devServer: {
|
|
350
|
-
host: "0.0.0.0",
|
|
351
|
-
allowedHosts: "all",
|
|
352
|
-
port: "auto",
|
|
353
|
-
// hot: true, // TODO: What does 'only' do? https://webpack.js.org/configuration/dev-server/#devserverhot
|
|
354
|
-
hot: "only", // TODO: What does 'only' do? https://webpack.js.org/configuration/dev-server/#devserverhot
|
|
355
|
-
client: {
|
|
356
|
-
logging: "info",
|
|
357
|
-
overlay: {
|
|
358
|
-
errors: true,
|
|
359
|
-
warnings: true,
|
|
360
|
-
runtimeErrors: (error) => {
|
|
361
|
-
// specific errors can be inspected and handled individually
|
|
362
|
-
// https://webpack.js.org/configuration/dev-server/#overlay
|
|
363
|
-
// console.log("webpack devServer runtimeError:", error);
|
|
364
|
-
return false;
|
|
365
|
-
},
|
|
366
|
-
},
|
|
367
|
-
reconnect: 30,
|
|
368
|
-
// webSocketURL: {
|
|
369
|
-
// port: parseInt(process.env.PORT), // external port, so websockets hit the right endpoint
|
|
370
|
-
// },
|
|
371
|
-
},
|
|
372
|
-
// webSocketServer: "ws",
|
|
373
|
-
// static: {
|
|
374
|
-
// // TODO: Should contentBase be `false` when there's a proxy?
|
|
375
|
-
// directory: path.join("/usr/src/site/", config.contentBase),
|
|
376
|
-
// /*
|
|
377
|
-
// * TODO: Poll options were enabled as a workaround for Docker-win volume inotify
|
|
378
|
-
// * issues. Looking to make this conditional...
|
|
379
|
-
// * Maybe defined `isWindows` or `hasiNotify` for assigning a value
|
|
380
|
-
// * Placeholder defined at the top of the file.
|
|
381
|
-
// * For now, `usePolling` is a boolean (set to true)
|
|
382
|
-
// * ref: https://github.com/docker/for-win/issues/56
|
|
383
|
-
// * https://www.npmjs.com/package/is-windows
|
|
384
|
-
// * TODO: Safe to remove?
|
|
385
|
-
// * TODO: Test on vanilla Windows (should now work in WSL)
|
|
386
|
-
// */
|
|
387
|
-
|
|
388
|
-
// watch: {
|
|
389
|
-
// poll: usePolling && pollInterval,
|
|
390
|
-
// ignored: ["node_modules", "vendor"],
|
|
391
|
-
// },
|
|
392
|
-
// },
|
|
393
|
-
|
|
394
|
-
devMiddleware: {
|
|
395
|
-
index: false, // enable root proxying
|
|
396
|
-
|
|
397
|
-
writeToDisk: (filePath) => {
|
|
398
|
-
/**
|
|
399
|
-
* Note: If this is an async function, it will write everything to disk
|
|
400
|
-
*
|
|
401
|
-
* Never write hot-update files to disk.
|
|
402
|
-
*/
|
|
403
|
-
// vendors-node_modules_mini-css-extract-plugin_dist_hmr_hotModuleReplacement_js-node_modules_we-780fe4.js.map
|
|
404
|
-
if (/.+(hot-update)\.(js|json|js\.map)$/.test(filePath)) {
|
|
405
|
-
return false;
|
|
406
|
-
}
|
|
407
|
-
// SHORT_CIRCUIT FOR TESTING
|
|
408
|
-
return true;
|
|
409
|
-
|
|
410
|
-
if (/.+\.(svg|json|php|jpg|png)$/.test(filePath)) {
|
|
411
|
-
const fileStat = statSync(filePath, { throwIfNoEntry: false });
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Always write SVG, PHP & JSON files
|
|
415
|
-
*/
|
|
416
|
-
if (/.+\.(svg|json|php)$/.test(filePath)) {
|
|
417
|
-
return true;
|
|
418
|
-
} else {
|
|
419
|
-
/**
|
|
420
|
-
* Write any images under 100k and anything not yet on disk
|
|
421
|
-
*/
|
|
422
|
-
if (!fileStat || fileStat.size < 100 * 1024) {
|
|
423
|
-
return true;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* TODO: This might all be unnecessary. Webpack seems to be doing a good job with its native caching
|
|
427
|
-
*/
|
|
428
|
-
// const randOffset = Math.random() * 300000; // 0-5 minutes
|
|
429
|
-
// const expired = new Date() - fileStat.mtime > randOffset;
|
|
430
|
-
// const relPath = filePath.replace(config.dist, "dist");
|
|
431
|
-
// if (expired) {
|
|
432
|
-
// console.log("DEBUG writeToDisk:", { replacing: relPath });
|
|
433
|
-
// return true;
|
|
434
|
-
// }
|
|
435
|
-
// console.log("DEBUG writeToDisk:", { cached: relPath });
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return false;
|
|
439
|
-
},
|
|
440
|
-
// stats,
|
|
441
|
-
// stats: 'verbose',
|
|
442
|
-
},
|
|
443
|
-
|
|
444
|
-
// NOTE: trying to make injection conditional so wp-admin stops reloading
|
|
445
|
-
// injectClient: compilerConfig => {
|
|
446
|
-
// console.log(compilerConfig);
|
|
447
|
-
// return true;
|
|
448
|
-
// },
|
|
449
|
-
|
|
450
|
-
onListening: (devServer) => {
|
|
451
|
-
const port = devServer.server.address().port;
|
|
452
|
-
devServer.compiler.options.devServer.port =
|
|
453
|
-
devServer.server.address().port;
|
|
454
|
-
devServer.compiler._devServer = devServer;
|
|
455
|
-
|
|
456
|
-
console.log("Listening on port:", port);
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
setupMiddlewares: (middlewares, devServer) => {
|
|
460
|
-
// devServer.compiler.options.devServer.port = devServer.options.port;
|
|
461
|
-
// devServer.compiler._devServer = devServer;
|
|
462
|
-
// if (!devServer) {
|
|
463
|
-
// throw new Error("webpack-dev-server is not defined");
|
|
464
|
-
// }
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* The `/inform` route is an annoying bit of code. Here's why:
|
|
468
|
-
* Ubiquity Wi-fi hardware frequently spams the shit out of their
|
|
469
|
-
* networks, specifically requesting the `/inform` route from
|
|
470
|
-
* every device. We still have some Ubiquity hardware on our
|
|
471
|
-
* networks, so dev servers were constantly responding to
|
|
472
|
-
* `/inform` requests with 404s, filling logs and cluttering
|
|
473
|
-
* terminals. So that's why this is here. I hate it.
|
|
474
|
-
*/
|
|
475
|
-
devServer.app.all("/inform", () => false);
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* The "/webpack/reload" endpoint will trigger a full devServer refresh
|
|
479
|
-
* Originally from our Browsersync implementation:
|
|
480
|
-
*
|
|
481
|
-
* https://github.com/ideasonpurpose/wp-theme-init/blob/ad8039c9757ffc3a0a0ed0adcc616a013fdc8604/src/ThemeInit.php#L202
|
|
482
|
-
*/
|
|
483
|
-
devServer.app.get("/webpack/reload", (req, res) => {
|
|
484
|
-
console.log(
|
|
485
|
-
chalk.yellow("Reload triggered by request to /webpack/reload"),
|
|
486
|
-
);
|
|
487
|
-
|
|
488
|
-
devServer.sendMessage(
|
|
489
|
-
devServer.webSocketServer.clients,
|
|
490
|
-
"content-changed",
|
|
491
|
-
);
|
|
492
|
-
res.json({ status: "Reloading!" });
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
return middlewares;
|
|
496
|
-
},
|
|
497
|
-
|
|
498
|
-
watchFiles: {
|
|
499
|
-
paths: [
|
|
500
|
-
path.resolve(config.src, "../**/*.{php,html,svg,json}"), // WordPress
|
|
501
|
-
],
|
|
502
|
-
options: {
|
|
503
|
-
ignored: [
|
|
504
|
-
"**/.git/**",
|
|
505
|
-
"**/vendor/**",
|
|
506
|
-
"**/node_modules/**",
|
|
507
|
-
"**/dist/**",
|
|
508
|
-
],
|
|
509
|
-
ignoreInitial: true,
|
|
510
|
-
ignorePermissionErrors: true,
|
|
511
|
-
/**
|
|
512
|
-
* TODO: Can polling be removed everywhere?
|
|
513
|
-
* @link https://github.com/docker/for-win/issues/56#issuecomment-576749639
|
|
514
|
-
*/
|
|
515
|
-
usePolling,
|
|
516
|
-
interval: pollInterval,
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
|
|
520
|
-
// ...(await devserverProxy(config)),
|
|
521
|
-
// TODO: Move
|
|
522
|
-
// ...(isProduction ? {} : await devserverProxy(config)),
|
|
523
|
-
...proxy,
|
|
524
|
-
},
|
|
525
|
-
|
|
526
|
-
mode: isProduction ? "production" : "development",
|
|
527
|
-
|
|
528
|
-
performance: {
|
|
529
|
-
hints: isProduction ? "warning" : false,
|
|
530
|
-
},
|
|
531
|
-
|
|
532
|
-
devtool,
|
|
533
|
-
|
|
534
|
-
plugins: [
|
|
535
|
-
new MiniCssExtractPlugin({
|
|
536
|
-
filename: isProduction ? "[name]-[contenthash:8].css" : "[name].css",
|
|
537
|
-
}),
|
|
538
|
-
|
|
539
|
-
new CopyPlugin({
|
|
540
|
-
patterns: [
|
|
541
|
-
{
|
|
542
|
-
from: "**/*",
|
|
543
|
-
globOptions: {
|
|
544
|
-
dot: true, // TODO: Dangerous? Why is this ever necessary?!
|
|
545
|
-
ignore: [
|
|
546
|
-
"**/{.gitignore,.DS_Store,*:Zone.Identifier}",
|
|
547
|
-
config.src + "/{block,blocks,fonts,js,sass}/**",
|
|
548
|
-
],
|
|
549
|
-
},
|
|
550
|
-
noErrorOnMissing: true,
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
from: config.src + "/{block,blocks}/**/block.json",
|
|
554
|
-
noErrorOnMissing: true,
|
|
555
|
-
}, // re-add block.json files for loading from PHP
|
|
556
|
-
],
|
|
557
|
-
options: { concurrency: 50 },
|
|
558
|
-
}),
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dependency-extraction-webpack-plugin/
|
|
562
|
-
*/
|
|
563
|
-
new DependencyExtractionWebpackPlugin(),
|
|
564
|
-
|
|
565
|
-
new DependencyManifestPlugin({
|
|
566
|
-
writeManifestFile: true,
|
|
567
|
-
manifestFile: config.manifestFile,
|
|
568
|
-
}),
|
|
569
|
-
|
|
570
|
-
new WatchRunReporterPlugin(),
|
|
571
|
-
|
|
572
|
-
new AfterDoneReporterPlugin({
|
|
573
|
-
echo: env && env.WEBPACK_SERVE,
|
|
574
|
-
// message:
|
|
575
|
-
// "Dev site " + chalk.blue.bold(`http://localhost:${process.env.PORT}`),
|
|
576
|
-
}),
|
|
577
|
-
|
|
578
|
-
new BundleAnalyzerPlugin({
|
|
579
|
-
analyzerMode: isProduction ? "static" : "disabled",
|
|
580
|
-
openAnalyzer: false,
|
|
581
|
-
reportFilename: new URL("webpack/stats/index.html", import.meta.url)
|
|
582
|
-
.pathname,
|
|
583
|
-
}),
|
|
584
|
-
],
|
|
585
|
-
optimization: {
|
|
586
|
-
splitChunks: {
|
|
587
|
-
chunks: "all",
|
|
588
|
-
},
|
|
589
|
-
minimizer: [
|
|
590
|
-
new EsbuildPlugin({
|
|
591
|
-
target: config.esTarget,
|
|
592
|
-
css: true,
|
|
593
|
-
}),
|
|
594
|
-
new ImageMinimizerPlugin({
|
|
595
|
-
severityError: "error",
|
|
596
|
-
|
|
597
|
-
minimizer: {
|
|
598
|
-
implementation: ImageMinimizerPlugin.sharpMinify,
|
|
599
|
-
|
|
600
|
-
options: {
|
|
601
|
-
/**
|
|
602
|
-
* Sharp options
|
|
603
|
-
*/
|
|
604
|
-
encodeOptions: {
|
|
605
|
-
jpeg: {
|
|
606
|
-
quality: 70,
|
|
607
|
-
mozjpeg: true,
|
|
608
|
-
},
|
|
609
|
-
png: {},
|
|
610
|
-
},
|
|
611
|
-
},
|
|
612
|
-
},
|
|
613
|
-
}),
|
|
614
|
-
],
|
|
615
|
-
},
|
|
616
|
-
};
|
|
617
|
-
};
|
|
1
|
+
export { webpackConfig as default } from "@ideasonpurpose/build-tools-wordpress";
|
package/lib/buildConfig.js
CHANGED
|
@@ -6,18 +6,37 @@ import url from "url";
|
|
|
6
6
|
// import { findLocalPort } from "../index.js";
|
|
7
7
|
|
|
8
8
|
// import defaultConfig from "../default.config.js";
|
|
9
|
+
/**
|
|
10
|
+
* Future node versions should import package.json directly:
|
|
11
|
+
* import packageJson from "./package.json" with { type: "json" };
|
|
12
|
+
*
|
|
13
|
+
* In the current node.js LTS v20, importing JSON throws the following warnings:
|
|
14
|
+
* (node:14509) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
15
|
+
* (Use `node --trace-warnings ...` to show where the warning was created)
|
|
16
|
+
*
|
|
17
|
+
* NOTE: This file does not work if the build runs from Docker. Inside a Docker volume, the
|
|
18
|
+
* theme name pulls instead from the docker image's package.json file, which will probably
|
|
19
|
+
* create a theme named 'iop-build-tools'.
|
|
20
|
+
*/
|
|
21
|
+
const pkgJsonPath = path.resolve(process.cwd(), "./package.json");
|
|
22
|
+
const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath));
|
|
23
|
+
// import packageJson from "./package.json" with { type: "json" };
|
|
24
|
+
|
|
25
|
+
const { name: themeName } = packageJson;
|
|
9
26
|
|
|
10
27
|
const defaultConfig = {
|
|
11
|
-
src:
|
|
12
|
-
dist:
|
|
13
|
-
entry: ["./js/
|
|
14
|
-
publicPath:
|
|
28
|
+
src: `./wp-content/themes/${themeName}/src`,
|
|
29
|
+
dist: `./wp-content/themes/${themeName}/dist`,
|
|
30
|
+
entry: ["./js/main.js", "./js/admin.js", "./js/editor.js"],
|
|
31
|
+
publicPath: `/wp-content/themes/${themeName}/dist/`,
|
|
32
|
+
|
|
15
33
|
contentBase: "/dist/", // TODO: Should this be false?
|
|
16
34
|
manifestFile: "./dependency-manifest.json",
|
|
17
35
|
sass: "sass-embedded",
|
|
18
36
|
esTarget: "es2020",
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
|
|
38
|
+
devtool: "source-map",
|
|
39
|
+
transpileDependencies: ["ansi-regex", "normalize-url"], // TODO: still necessary?
|
|
21
40
|
proxy: "wordpress",
|
|
22
41
|
};
|
|
23
42
|
|
|
@@ -39,6 +58,9 @@ export async function buildConfig(configFile = { config: {} }) {
|
|
|
39
58
|
* TODO: This warning can be removed once all process.env.NAME assignments are removed
|
|
40
59
|
* removed from project configuration files.
|
|
41
60
|
*/
|
|
61
|
+
|
|
62
|
+
configFile = configFile ?? { config: {} };
|
|
63
|
+
|
|
42
64
|
// if (configFile.filepath) {
|
|
43
65
|
// const rawConfigFile = fs.readFileSync(configFile.filepath);
|
|
44
66
|
// const packageJson = fs.readJsonSync(
|
|
@@ -57,6 +79,7 @@ export async function buildConfig(configFile = { config: {} }) {
|
|
|
57
79
|
/**
|
|
58
80
|
* Merge configFile onto defaults
|
|
59
81
|
*/
|
|
82
|
+
|
|
60
83
|
const config = { ...defaultConfig, ...configFile.config };
|
|
61
84
|
|
|
62
85
|
/**
|
|
@@ -86,7 +109,10 @@ export async function buildConfig(configFile = { config: {} }) {
|
|
|
86
109
|
* This lets us move up a level in the same way we could if cosmiConfig returned
|
|
87
110
|
* the path to a config.js or package.json file.
|
|
88
111
|
*/
|
|
89
|
-
configFile.filepath = configFile.filepath ||
|
|
112
|
+
configFile.filepath = configFile.filepath || pkgJsonPath;
|
|
113
|
+
|
|
114
|
+
// console.log({ configFile });
|
|
115
|
+
|
|
90
116
|
config.src = path.resolve(configFile.filepath, "..", config.src);
|
|
91
117
|
config.dist = path.resolve(configFile.filepath, "..", config.dist);
|
|
92
118
|
config.configFileUrl = url.pathToFileURL(configFile.filepath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ideasonpurpose/build-tools-wordpress",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Build scripts and dependencies for IOP's WordPress development environments.",
|
|
5
5
|
"homepage": "https://github.com/ideasonpurpose/build-tools-wordpress#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -31,21 +31,20 @@
|
|
|
31
31
|
},
|
|
32
32
|
"prettier": "@ideasonpurpose/prettier-config",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ideasonpurpose/prettier-config": "^0.0
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@rollup/plugin-commonjs": "^26.0.1",
|
|
34
|
+
"@ideasonpurpose/prettier-config": "^1.0.0",
|
|
35
|
+
"@ideasonpurpose/stylelint-config": "^1.1.0",
|
|
36
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
38
37
|
"@rollup/plugin-json": "^6.1.0",
|
|
39
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
38
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
40
39
|
"@svgr/webpack": "^8.1.0",
|
|
41
|
-
"@wordpress/dependency-extraction-webpack-plugin": "^6.
|
|
40
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.10.0",
|
|
42
41
|
"ansi-html": "^0.0.9",
|
|
43
42
|
"archiver": "^7.0.1",
|
|
44
43
|
"auto-changelog": "^2.5.0",
|
|
45
44
|
"autoprefixer": "^10.4.20",
|
|
46
45
|
"babel-loader": "^9.2.1",
|
|
47
46
|
"body-parser": "^1.20.3",
|
|
48
|
-
"caniuse-lite": "^1.0.
|
|
47
|
+
"caniuse-lite": "^1.0.30001669",
|
|
49
48
|
"chalk": "^5.3.0",
|
|
50
49
|
"chalk-cli": "^5.0.1",
|
|
51
50
|
"classnames": "^2.5.1",
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
"cssnano": "^7.0.6",
|
|
58
57
|
"dotenv": "^16.4.5",
|
|
59
58
|
"esbuild-loader": "^4.2.2",
|
|
60
|
-
"eslint": "^9.
|
|
59
|
+
"eslint": "^9.13.0",
|
|
61
60
|
"filesize": "^10.1.6",
|
|
62
61
|
"fs-extra": "^11.1.1",
|
|
63
62
|
"globby": "^14.0.2",
|
|
@@ -71,33 +70,29 @@
|
|
|
71
70
|
"postcss": "^8.4.47",
|
|
72
71
|
"postcss-loader": "^8.1.1",
|
|
73
72
|
"postcss-scss": "^4.0.9",
|
|
74
|
-
"prettier": "^3.3.3",
|
|
75
73
|
"pretty-hrtime": "^1.0.3",
|
|
76
74
|
"read-package-up": "^11.0.0",
|
|
77
75
|
"replacestream": "^4.0.3",
|
|
78
|
-
"sass": "^1.
|
|
79
|
-
"sass-embedded": "^1.
|
|
80
|
-
"sass-loader": "^16.0.
|
|
76
|
+
"sass": "^1.80.2",
|
|
77
|
+
"sass-embedded": "^1.80.2",
|
|
78
|
+
"sass-loader": "^16.0.2",
|
|
81
79
|
"semver": "^7.6.3",
|
|
82
80
|
"sharp": "^0.33.5",
|
|
83
81
|
"sort-package-json": "^2.10.1",
|
|
84
82
|
"string-length": "^6.0.0",
|
|
85
83
|
"style-loader": "^4.0.0",
|
|
86
|
-
"stylelint": "^16.9.0",
|
|
87
|
-
"stylelint-order": "^6.0.4",
|
|
88
|
-
"stylelint-prettier": "^5.0.2",
|
|
89
84
|
"svgo": "^3.3.2",
|
|
90
85
|
"svgo-loader": "^4.0.0",
|
|
91
86
|
"version-everything": "^0.11.4",
|
|
92
|
-
"webpack": "^5.
|
|
87
|
+
"webpack": "^5.95.0",
|
|
93
88
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
94
89
|
"webpack-cli": "^5.1.4",
|
|
95
90
|
"webpack-dev-middleware": "^7.4.2",
|
|
96
91
|
"webpack-dev-server": "^5.1.0"
|
|
97
92
|
},
|
|
98
93
|
"devDependencies": {
|
|
99
|
-
"@vitest/coverage-v8": "^2.1.
|
|
100
|
-
"vitest": "^2.1.
|
|
94
|
+
"@vitest/coverage-v8": "^2.1.3",
|
|
95
|
+
"vitest": "^2.1.3"
|
|
101
96
|
},
|
|
102
97
|
"version-everything": {
|
|
103
98
|
"files": [
|