@plaudit/webpack-extensions 1.2.2 → 2.0.0-beta.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.
|
@@ -11,18 +11,20 @@ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
|
11
11
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
12
12
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
13
13
|
const cssnano_1 = __importDefault(require("cssnano"));
|
|
14
|
+
function joinPossiblyAbsolutePaths(...paths) {
|
|
15
|
+
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
16
|
+
}
|
|
14
17
|
function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypoint) => entrypoint) {
|
|
15
18
|
for (const ep of Array.isArray(entrypoint) ? entrypoint : [entrypoint]) {
|
|
16
|
-
const mapped =
|
|
19
|
+
const mapped = joinPossiblyAbsolutePaths(dir, mapper(ep));
|
|
17
20
|
if (node_fs_1.default.existsSync(mapped)) {
|
|
18
21
|
const parsedEntrypoint = node_path_1.default.parse(mapped);
|
|
19
|
-
entrypoints[
|
|
22
|
+
entrypoints[joinPossiblyAbsolutePaths(node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name)] = { import: mapped };
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
function default_1(config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
24
|
-
const { legacyPostcssPlugins = false, variables =
|
|
25
|
-
} = config;
|
|
27
|
+
const { legacyPostcssPlugins = false, variables = ["variables.js", "preprocess/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p)).map(p => require(p))[0] ?? {}, } = config;
|
|
26
28
|
// Nano Config
|
|
27
29
|
// http://cssnano.co/guides/optimisations/ For the value to use click on one and then
|
|
28
30
|
const nanoConfig = {
|
|
@@ -71,6 +73,18 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
71
73
|
}
|
|
72
74
|
]
|
|
73
75
|
};
|
|
76
|
+
const cssLoader = require.resolve('css-loader');
|
|
77
|
+
if (cssLoader && webpackConfig.module?.rules) {
|
|
78
|
+
for (const rule of webpackConfig.module.rules) {
|
|
79
|
+
if (typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
|
|
80
|
+
for (const useElement of rule.use) {
|
|
81
|
+
if (typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
|
|
82
|
+
useElement.options['url'] = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
74
88
|
const postcssLoader = require.resolve('postcss-loader');
|
|
75
89
|
if (postcssLoader && webpackConfig.module?.rules) {
|
|
76
90
|
// Options: calc
|
|
@@ -82,7 +96,7 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
82
96
|
require("postcss-import")(),
|
|
83
97
|
require("@plaudit/postcss-silent-extend")(),
|
|
84
98
|
require("postcss-mixins")(),
|
|
85
|
-
require("
|
|
99
|
+
require("postcss-advanced-variables")(variables),
|
|
86
100
|
...(legacyPostcssPlugins ? [
|
|
87
101
|
require("postcss-quantity-queries")(),
|
|
88
102
|
require("postcss-short-position")(),
|
|
@@ -123,9 +137,11 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
123
137
|
}
|
|
124
138
|
}
|
|
125
139
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
126
|
-
return sources.map(([
|
|
127
|
-
const
|
|
128
|
-
const
|
|
140
|
+
return sources.map(([src, dest]) => {
|
|
141
|
+
const srcRoots = src.split(',');
|
|
142
|
+
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
143
|
+
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
|
|
144
|
+
const copyFiles = srcIsDirectory && src !== dest;
|
|
129
145
|
const plugins = webpackConfig.plugins ? [...webpackConfig.plugins] : [];
|
|
130
146
|
plugins.push(new fork_ts_checker_webpack_plugin_1.default({
|
|
131
147
|
typescript: {
|
|
@@ -139,19 +155,10 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
139
155
|
plugins.push(new BlockJSONStyleRemappingPlugin_1.default());
|
|
140
156
|
}
|
|
141
157
|
plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
path: node_path_1.default.join(process.cwd(), dest)
|
|
147
|
-
},
|
|
148
|
-
plugins: copyFiles
|
|
149
|
-
? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
|
|
150
|
-
? new copy_webpack_plugin_1.default({ patterns: [{ from: '**/(block.json|*.(php|twig|svg))', context: srcRoot, noErrorOnMissing: true }] })
|
|
151
|
-
: plugin)
|
|
152
|
-
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin'),
|
|
153
|
-
entry: node_fs_1.default.readdirSync(srcRoot, 'utf8')
|
|
154
|
-
.map(dir => node_path_1.default.join(srcRoot, dir))
|
|
158
|
+
let entry;
|
|
159
|
+
if (srcIsDirectory) {
|
|
160
|
+
entry = node_fs_1.default.readdirSync(srcRoot, 'utf8')
|
|
161
|
+
.map(dir => joinPossiblyAbsolutePaths(srcRoot, dir))
|
|
155
162
|
.filter(dir => node_fs_1.default.statSync(dir).isDirectory())
|
|
156
163
|
.reduce((entrypoints, dir) => {
|
|
157
164
|
try {
|
|
@@ -177,17 +184,17 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
177
184
|
else {
|
|
178
185
|
for (const [name, config] of Object.entries(entrypointsJSON)) {
|
|
179
186
|
if (typeof config === 'string') {
|
|
180
|
-
entrypoints[name] =
|
|
187
|
+
entrypoints[name] = joinPossiblyAbsolutePaths(dir, config);
|
|
181
188
|
}
|
|
182
189
|
else if (Array.isArray(config)) {
|
|
183
|
-
entrypoints[name] = config.map(c =>
|
|
190
|
+
entrypoints[name] = config.map(c => joinPossiblyAbsolutePaths(dir, c));
|
|
184
191
|
}
|
|
185
192
|
else {
|
|
186
193
|
if (typeof config.import === 'string') {
|
|
187
|
-
config.import =
|
|
194
|
+
config.import = joinPossiblyAbsolutePaths(dir, config.import);
|
|
188
195
|
}
|
|
189
196
|
else {
|
|
190
|
-
config.import = config.import.map(c =>
|
|
197
|
+
config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
|
|
191
198
|
}
|
|
192
199
|
entrypoints[name] = config;
|
|
193
200
|
}
|
|
@@ -200,7 +207,40 @@ function default_1(config, webpackConfig = require("@wordpress/scripts/config/we
|
|
|
200
207
|
}
|
|
201
208
|
}
|
|
202
209
|
return entrypoints;
|
|
203
|
-
}, {})
|
|
210
|
+
}, {});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const baseDest = node_path_1.default.basename(dest);
|
|
214
|
+
entry = {
|
|
215
|
+
[baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
let output;
|
|
219
|
+
if (srcIsDirectory) {
|
|
220
|
+
output = {
|
|
221
|
+
path: joinPossiblyAbsolutePaths(process.cwd(), dest)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
output = {
|
|
226
|
+
path: joinPossiblyAbsolutePaths(process.cwd(), node_path_1.default.dirname(dest))
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
...webpackConfig,
|
|
231
|
+
devtool: 'source-map',
|
|
232
|
+
output: {
|
|
233
|
+
...webpackConfig.output,
|
|
234
|
+
...output
|
|
235
|
+
},
|
|
236
|
+
plugins: copyFiles
|
|
237
|
+
? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
|
|
238
|
+
? new copy_webpack_plugin_1.default({ patterns: [{ from: '**/(block.json|*.(php|twig|svg))', context: srcRoot, noErrorOnMissing: true }] })
|
|
239
|
+
: plugin)
|
|
240
|
+
: (srcIsDirectory
|
|
241
|
+
? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
242
|
+
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
|
|
243
|
+
entry
|
|
204
244
|
};
|
|
205
245
|
});
|
|
206
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -13,29 +13,29 @@
|
|
|
13
13
|
"./wordpress-scripts-wrapper": "./build/wordpress-scripts-wrapper.js"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/node": "^20.2.
|
|
16
|
+
"@types/node": "^20.2.5",
|
|
17
17
|
"@types/webpack": "^5.28.1",
|
|
18
18
|
"@types/webpack-sources": "^3.2.0",
|
|
19
19
|
"postcss-load-config": "^4.0.1",
|
|
20
|
-
"postcss-loader": "^7.3.
|
|
20
|
+
"postcss-loader": "^7.3.2",
|
|
21
21
|
"ts-node": "^10.9.1",
|
|
22
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.1.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@plaudit/postcss-color-function": "^5.0.0",
|
|
26
26
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
27
27
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
28
|
-
"@plaudit/postcss-variables": "^1.0.0",
|
|
29
28
|
"@wordpress/scripts": "^26.4.0",
|
|
30
29
|
"autoprefixer": "^10.4.14",
|
|
31
30
|
"clean-webpack-plugin": "^4.0.0",
|
|
32
31
|
"copy-webpack-plugin": "^11.0.0",
|
|
33
32
|
"cssnano": "^6.0.1",
|
|
34
|
-
"eslint": "^8.
|
|
33
|
+
"eslint": "^8.42.0",
|
|
35
34
|
"eslint-plugin-jsdoc": "^43.1.1",
|
|
36
35
|
"fork-ts-checker-webpack-plugin": "^8.0.0",
|
|
37
|
-
"postcss": "^8.4.
|
|
38
|
-
"postcss-
|
|
36
|
+
"postcss": "^8.4.24",
|
|
37
|
+
"postcss-advanced-variables": "^3.0.1",
|
|
38
|
+
"postcss-calc": "^9.0.1",
|
|
39
39
|
"postcss-extend": "^1.0.5",
|
|
40
40
|
"postcss-fallback": "^0.1.0",
|
|
41
41
|
"postcss-import": "^15.1.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"postcss-short-spacing": "^4.0.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-dom": "^18.2.0",
|
|
54
|
-
"webpack": "^5.
|
|
54
|
+
"webpack": "^5.86.0",
|
|
55
55
|
"webpack-remove-empty-scripts": "^1.0.3",
|
|
56
56
|
"webpack-sources": "^3.2.3"
|
|
57
57
|
},
|