@plaudit/webpack-extensions 2.0.0-beta.7 → 2.0.0-beta.8

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.
@@ -34,7 +34,7 @@ class AdditionalDependencyInjectorPlugin {
34
34
  }
35
35
  const firstLine = node_fs_1.default.readFileSync(assetSource, 'utf8').trim().split(/\r?\n/)[0];
36
36
  if (firstLine.startsWith("//ADDITIONAL_DEPENDENCIES:")) {
37
- const additionalDependencies = firstLine.substring(26).trim().split(',');
37
+ const additionalDependencies = firstLine.substring(26).trim().split(',').map(dep => dep.trim());
38
38
  const seen = new Set();
39
39
  const additionalDeps = additionalDependencies.filter(dep => !seen.has(dep) && seen.add(dep)).sort().map(v => `'${v}'`).join(', ');
40
40
  if (additionalDeps) {
@@ -1 +1,8 @@
1
- export { default } from "./wordpress-scripts-wrapper/wordpressWebpackEntrypointWrapper";
1
+ import type { Configuration } from "webpack";
2
+ interface PlauditWordpressWebpackConfig {
3
+ legacyPostcssPlugins?: boolean;
4
+ variables?: Record<string, any>;
5
+ src: string[] | Record<string, string>;
6
+ }
7
+ declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration) => Configuration[];
8
+ export = _default;
@@ -2,7 +2,243 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = void 0;
7
- var wordpressWebpackEntrypointWrapper_1 = require("./wordpress-scripts-wrapper/wordpressWebpackEntrypointWrapper");
8
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(wordpressWebpackEntrypointWrapper_1).default; } });
5
+ const node_fs_1 = __importDefault(require("node:fs"));
6
+ const node_path_1 = __importDefault(require("node:path"));
7
+ const AdditionalDependencyInjectorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin"));
8
+ const BlockJSONStyleRemappingPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/BlockJSONStyleRemappingPlugin"));
9
+ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
10
+ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
11
+ const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
12
+ const cssnano_1 = __importDefault(require("cssnano"));
13
+ function joinPossiblyAbsolutePaths(...paths) {
14
+ return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
15
+ }
16
+ function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypoint) => entrypoint) {
17
+ for (const ep of Array.isArray(entrypoint) ? entrypoint : [entrypoint]) {
18
+ const mapped = joinPossiblyAbsolutePaths(dir, mapper(ep));
19
+ if (node_fs_1.default.existsSync(mapped)) {
20
+ const parsedEntrypoint = node_path_1.default.parse(mapped);
21
+ entrypoints[joinPossiblyAbsolutePaths(node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name)] = { import: mapped };
22
+ }
23
+ }
24
+ }
25
+ module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
26
+ 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;
27
+ // Nano Config
28
+ // http://cssnano.co/guides/optimisations/ For the value to use click on one and then
29
+ const nanoConfig = {
30
+ preset: [
31
+ 'cssnano-preset-default',
32
+ {
33
+ safe: true,
34
+ autoprefixer: false,
35
+ calc: false,
36
+ colormin: true,
37
+ convertValues: false,
38
+ discardComments: {
39
+ remove(comment) {
40
+ const commentKeepRegexp = /^!|@cms|@preserve|@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\bBSD\b|\bISCL\b|\(c\)|\bLicense\b|\bCopyright\b/i;
41
+ return !commentKeepRegexp.test(comment);
42
+ }
43
+ },
44
+ discardDuplicates: true,
45
+ discardEmpty: true,
46
+ discardOverridden: true,
47
+ discardUnused: false,
48
+ mergeIdents: false,
49
+ mergeLonghand: true,
50
+ mergeRules: false,
51
+ minifyFontValues: true,
52
+ minifyGradients: true,
53
+ minifyParams: true,
54
+ minifySelectors: true,
55
+ normalizeCharset: true,
56
+ normalizeDisplayValues: true,
57
+ normalizePositions: true,
58
+ normalizeRepeatStyle: true,
59
+ normalizeString: true,
60
+ normalizeTimingFunctions: true,
61
+ normalizeUnicode: true,
62
+ normalizeUrl: true,
63
+ normalizeWhitespace: true,
64
+ orderedValues: true,
65
+ reduceIdents: false,
66
+ reduceInitial: true,
67
+ reduceTransforms: true,
68
+ svgo: false,
69
+ uniqueSelectors: true,
70
+ zindex: false,
71
+ filterPlugins: false // I don't know where this one came from. It is not listed in the documentation.
72
+ }
73
+ ]
74
+ };
75
+ const cssLoader = require.resolve('css-loader');
76
+ if (cssLoader && webpackConfig.module?.rules) {
77
+ for (const rule of webpackConfig.module.rules) {
78
+ if (typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
79
+ for (const useElement of rule.use) {
80
+ if (typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
81
+ useElement.options['url'] = false;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ if (webpackConfig.module?.rules) {
88
+ // Options: calc
89
+ const calcOptions = { precision: 4, mediaQueries: true, selectors: true };
90
+ // Options: autoprefixerOptions
91
+ const autoprefixerOptions = { grid: "autoplace" };
92
+ const postcssConfig = {
93
+ plugins: [
94
+ require("postcss-import")(),
95
+ require("@plaudit/postcss-silent-extend")(),
96
+ require("postcss-mixins")(),
97
+ require("@plaudit/postcss-variables")(variables),
98
+ ...(legacyPostcssPlugins ? [
99
+ require("postcss-quantity-queries")(),
100
+ require("postcss-short-position")(),
101
+ require("postcss-short-size")(),
102
+ require("postcss-short-spacing")(),
103
+ require("postcss-fallback")() // Legacy
104
+ ] : []),
105
+ require("postcss-property-lookup")({ logLevel: "warn" }),
106
+ require("@plaudit/postcss-strip-units")(),
107
+ require("postcss-media-minmax")(),
108
+ require("postcss-inline-svg")(),
109
+ require("postcss-nested")(),
110
+ require("postcss-calc")(calcOptions),
111
+ require("@plaudit/postcss-color-function")(),
112
+ require("autoprefixer")(autoprefixerOptions),
113
+ require("postcss-reporter")({ clearReportedMessages: true }),
114
+ (0, cssnano_1.default)(nanoConfig)
115
+ ]
116
+ };
117
+ for (const rule of webpackConfig.module.rules) {
118
+ if (typeof rule === 'object' && Array.isArray(rule.use)) {
119
+ for (const useItem of rule.use) {
120
+ if (typeof useItem === 'object' && typeof useItem.options === 'object') {
121
+ if (useItem.options["sourceMap"] === false) {
122
+ useItem.options["sourceMap"] = true;
123
+ }
124
+ if (useItem.loader?.includes('postcss-loader')) {
125
+ if (useItem.options["postcssOptions"]) {
126
+ useItem.options["postcssOptions"] = { ...useItem.options["postcssOptions"], ...postcssConfig, sourceMap: true };
127
+ }
128
+ else {
129
+ useItem.options["postcssOptions"] = { ...postcssConfig, sourceMap: true };
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
138
+ return sources.map(([src, dest]) => {
139
+ const srcRoots = src.split(',');
140
+ const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
141
+ const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
142
+ const copyFiles = srcIsDirectory && src !== dest;
143
+ const plugins = webpackConfig.plugins ? [...webpackConfig.plugins] : [];
144
+ plugins.push(new fork_ts_checker_webpack_plugin_1.default({
145
+ typescript: {
146
+ diagnosticOptions: {
147
+ semantic: true,
148
+ syntactic: true,
149
+ }
150
+ }
151
+ }), new webpack_remove_empty_scripts_1.default({ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS, extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'] }));
152
+ if (copyFiles) {
153
+ plugins.push(new BlockJSONStyleRemappingPlugin_1.default());
154
+ }
155
+ plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
156
+ let entry;
157
+ if (srcIsDirectory) {
158
+ entry = node_fs_1.default.readdirSync(srcRoot, 'utf8')
159
+ .map(dir => joinPossiblyAbsolutePaths(srcRoot, dir))
160
+ .filter(dir => node_fs_1.default.statSync(dir).isDirectory())
161
+ .reduce((entrypoints, dir) => {
162
+ try {
163
+ const blockJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'block.json'), 'utf8'));
164
+ for (const key of ["editorStyle", "style", "editorScript", "viewScript", "script"]) {
165
+ if (key in blockJSON) {
166
+ addEntryPointWithMapper(entrypoints, blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep);
167
+ }
168
+ }
169
+ }
170
+ catch (e) {
171
+ try {
172
+ const packageJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'package.json'), 'utf8'));
173
+ addEntryPointWithMapper(entrypoints, packageJSON['main'], dir);
174
+ addEntryPointWithMapper(entrypoints, packageJSON['style'], dir);
175
+ }
176
+ catch (e) {
177
+ try {
178
+ const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
179
+ if (Array.isArray(entrypointsJSON)) {
180
+ addEntryPointWithMapper(entrypoints, entrypointsJSON, dir);
181
+ }
182
+ else {
183
+ for (const [name, config] of Object.entries(entrypointsJSON)) {
184
+ if (typeof config === 'string') {
185
+ entrypoints[name] = joinPossiblyAbsolutePaths(dir, config);
186
+ }
187
+ else if (Array.isArray(config)) {
188
+ entrypoints[name] = config.map(c => joinPossiblyAbsolutePaths(dir, c));
189
+ }
190
+ else {
191
+ if (typeof config.import === 'string') {
192
+ config.import = joinPossiblyAbsolutePaths(dir, config.import);
193
+ }
194
+ else {
195
+ config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
196
+ }
197
+ entrypoints[name] = config;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ catch (e) {
203
+ // This just means that the directory doesn't contain any declared entrypoints.
204
+ }
205
+ }
206
+ }
207
+ return entrypoints;
208
+ }, {});
209
+ }
210
+ else {
211
+ const baseDest = node_path_1.default.basename(dest);
212
+ entry = {
213
+ [baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
214
+ };
215
+ }
216
+ let output;
217
+ if (srcIsDirectory) {
218
+ output = {
219
+ path: joinPossiblyAbsolutePaths(process.cwd(), dest)
220
+ };
221
+ }
222
+ else {
223
+ output = {
224
+ path: joinPossiblyAbsolutePaths(process.cwd(), node_path_1.default.dirname(dest))
225
+ };
226
+ }
227
+ return {
228
+ ...webpackConfig,
229
+ devtool: 'source-map',
230
+ output: {
231
+ ...webpackConfig.output,
232
+ ...output
233
+ },
234
+ plugins: copyFiles
235
+ ? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
236
+ ? new copy_webpack_plugin_1.default({ patterns: [{ from: '**/(block.json|*.(php|twig|svg))', context: srcRoot, noErrorOnMissing: true }] })
237
+ : plugin)
238
+ : (srcIsDirectory
239
+ ? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
240
+ : plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
241
+ entry
242
+ };
243
+ });
244
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.8",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",
@@ -1,7 +0,0 @@
1
- import type { Configuration } from "webpack";
2
- export interface PlauditWordpressWebpackConfig {
3
- legacyPostcssPlugins?: boolean;
4
- variables?: Record<string, any>;
5
- src: string[] | Record<string, string>;
6
- }
7
- export default function (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration): Configuration[];
@@ -1,246 +0,0 @@
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
- const node_fs_1 = __importDefault(require("node:fs"));
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const AdditionalDependencyInjectorPlugin_1 = __importDefault(require("./AdditionalDependencyInjectorPlugin"));
9
- const BlockJSONStyleRemappingPlugin_1 = __importDefault(require("./BlockJSONStyleRemappingPlugin"));
10
- const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
11
- const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
12
- const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
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
- }
17
- function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypoint) => entrypoint) {
18
- for (const ep of Array.isArray(entrypoint) ? entrypoint : [entrypoint]) {
19
- const mapped = joinPossiblyAbsolutePaths(dir, mapper(ep));
20
- if (node_fs_1.default.existsSync(mapped)) {
21
- const parsedEntrypoint = node_path_1.default.parse(mapped);
22
- entrypoints[joinPossiblyAbsolutePaths(node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name)] = { import: mapped };
23
- }
24
- }
25
- }
26
- function default_1(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
- };
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
- }
88
- if (webpackConfig.module?.rules) {
89
- // Options: calc
90
- const calcOptions = { precision: 4, mediaQueries: true, selectors: true };
91
- // Options: autoprefixerOptions
92
- const autoprefixerOptions = { grid: "autoplace" };
93
- const postcssConfig = {
94
- plugins: [
95
- require("postcss-import")(),
96
- require("@plaudit/postcss-silent-extend")(),
97
- require("postcss-mixins")(),
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
- };
118
- for (const rule of webpackConfig.module.rules) {
119
- if (typeof rule === 'object' && Array.isArray(rule.use)) {
120
- for (const useItem of rule.use) {
121
- if (typeof useItem === 'object' && typeof useItem.options === 'object') {
122
- if (useItem.options["sourceMap"] === false) {
123
- useItem.options["sourceMap"] = true;
124
- }
125
- if (useItem.loader?.includes('postcss-loader')) {
126
- if (useItem.options["postcssOptions"]) {
127
- useItem.options["postcssOptions"] = { ...useItem.options["postcssOptions"], ...postcssConfig, sourceMap: true };
128
- }
129
- else {
130
- useItem.options["postcssOptions"] = { ...postcssConfig, sourceMap: true };
131
- }
132
- }
133
- }
134
- }
135
- }
136
- }
137
- }
138
- const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
139
- return sources.map(([src, dest]) => {
140
- const srcRoots = src.split(',');
141
- const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
142
- const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
143
- const copyFiles = srcIsDirectory && src !== dest;
144
- const plugins = webpackConfig.plugins ? [...webpackConfig.plugins] : [];
145
- plugins.push(new fork_ts_checker_webpack_plugin_1.default({
146
- typescript: {
147
- diagnosticOptions: {
148
- semantic: true,
149
- syntactic: true,
150
- }
151
- }
152
- }), new webpack_remove_empty_scripts_1.default({ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS, extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'] }));
153
- if (copyFiles) {
154
- plugins.push(new BlockJSONStyleRemappingPlugin_1.default());
155
- }
156
- plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
157
- let entry;
158
- if (srcIsDirectory) {
159
- entry = node_fs_1.default.readdirSync(srcRoot, 'utf8')
160
- .map(dir => joinPossiblyAbsolutePaths(srcRoot, dir))
161
- .filter(dir => node_fs_1.default.statSync(dir).isDirectory())
162
- .reduce((entrypoints, dir) => {
163
- try {
164
- const blockJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'block.json'), 'utf8'));
165
- for (const key of ["editorStyle", "style", "editorScript", "viewScript", "script"]) {
166
- if (key in blockJSON) {
167
- addEntryPointWithMapper(entrypoints, blockJSON[key], dir, ep => ep.startsWith("file:") ? ep.substring(5) : ep);
168
- }
169
- }
170
- }
171
- catch (e) {
172
- try {
173
- const packageJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'package.json'), 'utf8'));
174
- addEntryPointWithMapper(entrypoints, packageJSON['main'], dir);
175
- addEntryPointWithMapper(entrypoints, packageJSON['style'], dir);
176
- }
177
- catch (e) {
178
- try {
179
- const entrypointsJSON = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(dir, 'entrypoints.json'), 'utf8'));
180
- if (Array.isArray(entrypointsJSON)) {
181
- addEntryPointWithMapper(entrypoints, entrypointsJSON, dir);
182
- }
183
- else {
184
- for (const [name, config] of Object.entries(entrypointsJSON)) {
185
- if (typeof config === 'string') {
186
- entrypoints[name] = joinPossiblyAbsolutePaths(dir, config);
187
- }
188
- else if (Array.isArray(config)) {
189
- entrypoints[name] = config.map(c => joinPossiblyAbsolutePaths(dir, c));
190
- }
191
- else {
192
- if (typeof config.import === 'string') {
193
- config.import = joinPossiblyAbsolutePaths(dir, config.import);
194
- }
195
- else {
196
- config.import = config.import.map(c => joinPossiblyAbsolutePaths(dir, c));
197
- }
198
- entrypoints[name] = config;
199
- }
200
- }
201
- }
202
- }
203
- catch (e) {
204
- // This just means that the directory doesn't contain any declared entrypoints.
205
- }
206
- }
207
- }
208
- return entrypoints;
209
- }, {});
210
- }
211
- else {
212
- const baseDest = node_path_1.default.basename(dest);
213
- entry = {
214
- [baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
215
- };
216
- }
217
- let output;
218
- if (srcIsDirectory) {
219
- output = {
220
- path: joinPossiblyAbsolutePaths(process.cwd(), dest)
221
- };
222
- }
223
- else {
224
- output = {
225
- path: joinPossiblyAbsolutePaths(process.cwd(), node_path_1.default.dirname(dest))
226
- };
227
- }
228
- return {
229
- ...webpackConfig,
230
- devtool: 'source-map',
231
- output: {
232
- ...webpackConfig.output,
233
- ...output
234
- },
235
- plugins: copyFiles
236
- ? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
237
- ? new copy_webpack_plugin_1.default({ patterns: [{ from: '**/(block.json|*.(php|twig|svg))', context: srcRoot, noErrorOnMissing: true }] })
238
- : plugin)
239
- : (srcIsDirectory
240
- ? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
241
- : plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
242
- entry
243
- };
244
- });
245
- }
246
- exports.default = default_1;