@plaudit/webpack-extensions 2.0.0 → 2.0.2
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.
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.postcssConfigBuilder = void 0;
|
|
7
|
+
const cssnano_1 = __importDefault(require("cssnano"));
|
|
8
|
+
// Options: calc
|
|
9
|
+
const calcOptions = { precision: 4, mediaQueries: true, selectors: true };
|
|
10
|
+
// Options: autoprefixerOptions
|
|
11
|
+
const autoprefixerOptions = { grid: "autoplace" };
|
|
12
|
+
// Nano Config
|
|
13
|
+
// http://cssnano.co/guides/optimisations/ For the value to use click on one and then
|
|
14
|
+
const nanoConfig = {
|
|
15
|
+
preset: [
|
|
16
|
+
'cssnano-preset-default',
|
|
17
|
+
{
|
|
18
|
+
safe: true,
|
|
19
|
+
autoprefixer: false,
|
|
20
|
+
calc: false,
|
|
21
|
+
colormin: true,
|
|
22
|
+
convertValues: false,
|
|
23
|
+
discardComments: {
|
|
24
|
+
remove(comment) {
|
|
25
|
+
const commentKeepRegexp = /^!|@cms|@preserve|@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\bBSD\b|\bISCL\b|\(c\)|\bLicense\b|\bCopyright\b/i;
|
|
26
|
+
return !commentKeepRegexp.test(comment);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
discardDuplicates: true,
|
|
30
|
+
discardEmpty: true,
|
|
31
|
+
discardOverridden: true,
|
|
32
|
+
discardUnused: false,
|
|
33
|
+
mergeIdents: false,
|
|
34
|
+
mergeLonghand: true,
|
|
35
|
+
mergeRules: false,
|
|
36
|
+
minifyFontValues: true,
|
|
37
|
+
minifyGradients: true,
|
|
38
|
+
minifyParams: true,
|
|
39
|
+
minifySelectors: true,
|
|
40
|
+
normalizeCharset: true,
|
|
41
|
+
normalizeDisplayValues: true,
|
|
42
|
+
normalizePositions: true,
|
|
43
|
+
normalizeRepeatStyle: true,
|
|
44
|
+
normalizeString: true,
|
|
45
|
+
normalizeTimingFunctions: true,
|
|
46
|
+
normalizeUnicode: true,
|
|
47
|
+
normalizeUrl: true,
|
|
48
|
+
normalizeWhitespace: true,
|
|
49
|
+
orderedValues: true,
|
|
50
|
+
reduceIdents: false,
|
|
51
|
+
reduceInitial: true,
|
|
52
|
+
reduceTransforms: true,
|
|
53
|
+
svgo: false,
|
|
54
|
+
uniqueSelectors: true,
|
|
55
|
+
zindex: false,
|
|
56
|
+
filterPlugins: false // I don't know where this one came from. It is not listed in the documentation.
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
};
|
|
60
|
+
function postcssConfigBuilder(verbose, legacyPostcssPlugins, variables) {
|
|
61
|
+
return {
|
|
62
|
+
plugins: [
|
|
63
|
+
require("postcss-import")(),
|
|
64
|
+
require("@plaudit/postcss-silent-extend")({ warnOfUnused: verbose }),
|
|
65
|
+
require("postcss-mixins")(),
|
|
66
|
+
require("@plaudit/postcss-variables")({ variables }),
|
|
67
|
+
...(legacyPostcssPlugins ? [
|
|
68
|
+
require("postcss-quantity-queries")(),
|
|
69
|
+
require("postcss-short-position")(),
|
|
70
|
+
require("postcss-short-size")(),
|
|
71
|
+
require("postcss-short-spacing")(),
|
|
72
|
+
require("postcss-fallback")() // Legacy
|
|
73
|
+
] : []),
|
|
74
|
+
require("postcss-property-lookup")({ logLevel: "warn" }),
|
|
75
|
+
require("@plaudit/postcss-strip-units")(),
|
|
76
|
+
require("postcss-media-minmax")(),
|
|
77
|
+
require("postcss-inline-svg")(),
|
|
78
|
+
require("postcss-nested")(),
|
|
79
|
+
require("postcss-calc")(calcOptions),
|
|
80
|
+
require("@plaudit/postcss-color-function")(),
|
|
81
|
+
require("autoprefixer")(autoprefixerOptions),
|
|
82
|
+
require("postcss-reporter")({ clearReportedMessages: true }),
|
|
83
|
+
(0, cssnano_1.default)(nanoConfig)
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.postcssConfigBuilder = postcssConfigBuilder;
|
|
@@ -2,6 +2,7 @@ import type { Configuration } from "webpack";
|
|
|
2
2
|
interface PlauditWordpressWebpackConfig {
|
|
3
3
|
legacyPostcssPlugins?: boolean;
|
|
4
4
|
variables?: Record<string, any>;
|
|
5
|
+
verbose?: boolean;
|
|
5
6
|
src: string[] | Record<string, string>;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration) => Configuration[];
|
|
@@ -10,7 +10,7 @@ const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webp
|
|
|
10
10
|
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
|
-
const
|
|
13
|
+
const static_configs_1 = require("./wordpress-scripts-wrapper/static-configs");
|
|
14
14
|
function joinPossiblyAbsolutePaths(...paths) {
|
|
15
15
|
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
16
16
|
}
|
|
@@ -24,55 +24,7 @@ function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypo
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.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;
|
|
28
|
-
// Nano Config
|
|
29
|
-
// http://cssnano.co/guides/optimisations/ For the value to use click on one and then
|
|
30
|
-
const nanoConfig = {
|
|
31
|
-
preset: [
|
|
32
|
-
'cssnano-preset-default',
|
|
33
|
-
{
|
|
34
|
-
safe: true,
|
|
35
|
-
autoprefixer: false,
|
|
36
|
-
calc: false,
|
|
37
|
-
colormin: true,
|
|
38
|
-
convertValues: false,
|
|
39
|
-
discardComments: {
|
|
40
|
-
remove(comment) {
|
|
41
|
-
const commentKeepRegexp = /^!|@cms|@preserve|@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\bBSD\b|\bISCL\b|\(c\)|\bLicense\b|\bCopyright\b/i;
|
|
42
|
-
return !commentKeepRegexp.test(comment);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
discardDuplicates: true,
|
|
46
|
-
discardEmpty: true,
|
|
47
|
-
discardOverridden: true,
|
|
48
|
-
discardUnused: false,
|
|
49
|
-
mergeIdents: false,
|
|
50
|
-
mergeLonghand: true,
|
|
51
|
-
mergeRules: false,
|
|
52
|
-
minifyFontValues: true,
|
|
53
|
-
minifyGradients: true,
|
|
54
|
-
minifyParams: true,
|
|
55
|
-
minifySelectors: true,
|
|
56
|
-
normalizeCharset: true,
|
|
57
|
-
normalizeDisplayValues: true,
|
|
58
|
-
normalizePositions: true,
|
|
59
|
-
normalizeRepeatStyle: true,
|
|
60
|
-
normalizeString: true,
|
|
61
|
-
normalizeTimingFunctions: true,
|
|
62
|
-
normalizeUnicode: true,
|
|
63
|
-
normalizeUrl: true,
|
|
64
|
-
normalizeWhitespace: true,
|
|
65
|
-
orderedValues: true,
|
|
66
|
-
reduceIdents: false,
|
|
67
|
-
reduceInitial: true,
|
|
68
|
-
reduceTransforms: true,
|
|
69
|
-
svgo: false,
|
|
70
|
-
uniqueSelectors: true,
|
|
71
|
-
zindex: false,
|
|
72
|
-
filterPlugins: false // I don't know where this one came from. It is not listed in the documentation.
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
};
|
|
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] ?? {}, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
|
|
76
28
|
const cssLoader = require.resolve('css-loader');
|
|
77
29
|
if (cssLoader && webpackConfig.module?.rules) {
|
|
78
30
|
for (const rule of webpackConfig.module.rules) {
|
|
@@ -85,36 +37,17 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
85
37
|
}
|
|
86
38
|
}
|
|
87
39
|
}
|
|
40
|
+
let currentEntrypoint = '';
|
|
88
41
|
if (webpackConfig.module?.rules) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
require("@plaudit/postcss-variables")(variables),
|
|
99
|
-
...(legacyPostcssPlugins ? [
|
|
100
|
-
require("postcss-quantity-queries")(),
|
|
101
|
-
require("postcss-short-position")(),
|
|
102
|
-
require("postcss-short-size")(),
|
|
103
|
-
require("postcss-short-spacing")(),
|
|
104
|
-
require("postcss-fallback")() // Legacy
|
|
105
|
-
] : []),
|
|
106
|
-
require("postcss-property-lookup")({ logLevel: "warn" }),
|
|
107
|
-
require("@plaudit/postcss-strip-units")(),
|
|
108
|
-
require("postcss-media-minmax")(),
|
|
109
|
-
require("postcss-inline-svg")(),
|
|
110
|
-
require("postcss-nested")(),
|
|
111
|
-
require("postcss-calc")(calcOptions),
|
|
112
|
-
require("@plaudit/postcss-color-function")(),
|
|
113
|
-
require("autoprefixer")(autoprefixerOptions),
|
|
114
|
-
require("postcss-reporter")({ clearReportedMessages: true }),
|
|
115
|
-
(0, cssnano_1.default)(nanoConfig)
|
|
116
|
-
]
|
|
117
|
-
};
|
|
42
|
+
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, legacyPostcssPlugins, (name) => {
|
|
43
|
+
if (variables[name]) {
|
|
44
|
+
return variables[name];
|
|
45
|
+
}
|
|
46
|
+
if (name === 'ENV') { // This is purely a backwards-compatibility issue.
|
|
47
|
+
return currentEntrypoint.endsWith('public.pcss') ? 'PUBLIC' : (currentEntrypoint.endsWith('block-editor.pcss') ? 'EDITOR' : '');
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
});
|
|
118
51
|
for (const rule of webpackConfig.module.rules) {
|
|
119
52
|
if (typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
120
53
|
for (const useItem of rule.use) {
|
|
@@ -138,6 +71,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
138
71
|
let first = true;
|
|
139
72
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
140
73
|
return sources.map(([src, dest]) => {
|
|
74
|
+
currentEntrypoint = src;
|
|
141
75
|
const srcRoots = src.split(',');
|
|
142
76
|
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
143
77
|
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
|
|
@@ -157,7 +91,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
157
91
|
plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
|
|
158
92
|
if (first) {
|
|
159
93
|
first = false;
|
|
160
|
-
if (process.argv.includes('--browser-sync')) {
|
|
94
|
+
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
161
95
|
plugins.push(new browser_sync_webpack_plugin_1.default({
|
|
162
96
|
host: 'localhost',
|
|
163
97
|
port: 3000,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/browser-sync-webpack-plugin": "^2.2.2",
|
|
17
|
-
"@types/node": "^20.
|
|
17
|
+
"@types/node": "^20.3.0",
|
|
18
18
|
"@types/tapable": "^2.2.3",
|
|
19
19
|
"@types/webpack": "^5.28.1",
|
|
20
20
|
"@types/webpack-sources": "^3.2.0",
|
|
21
21
|
"postcss-load-config": "^4.0.1",
|
|
22
|
-
"postcss-loader": "^7.3.
|
|
22
|
+
"postcss-loader": "^7.3.3",
|
|
23
23
|
"ts-node": "^10.9.1",
|
|
24
24
|
"typescript": "^5.1.3"
|
|
25
25
|
},
|