weboptimizer 4.0.1 → 4.0.3
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/browser.js +2 -2
- package/configurator.d.ts +3 -3
- package/configurator.js +26 -4
- package/ejsLoader.js +3 -3
- package/helper.d.ts +4 -3
- package/helper.js +14 -2
- package/index.d.ts +2 -2
- package/index.js +25 -8
- package/package.json +5 -2
- package/plugins/HTMLTransformation.js +2 -2
- package/plugins/InPlaceAssetsIntoHTML.js +1 -1
- package/stylelintConfigurator.js +2 -2
- package/type.d.ts +7 -7
- package/type.js +0 -13
- package/webpackConfigurator.js +66 -9
package/browser.js
CHANGED
|
@@ -20,8 +20,8 @@ import "core-js/modules/es.array.push.js";
|
|
|
20
20
|
import { CONSOLE_METHODS, Logger, ProcedureFunction, timeout } from 'clientnode';
|
|
21
21
|
import { DOMWindow, VirtualConsole } from 'jsdom';
|
|
22
22
|
import { LoaderContext } from 'webpack';
|
|
23
|
-
import { LoaderConfiguration } from
|
|
24
|
-
import { Browser, InitializedBrowser } from
|
|
23
|
+
import { LoaderConfiguration } from "./ejsLoader.js";
|
|
24
|
+
import { Browser, InitializedBrowser } from "./type.js";
|
|
25
25
|
// endregion
|
|
26
26
|
// region declaration
|
|
27
27
|
|
package/configurator.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { ResolvedConfiguration } from './type';
|
|
2
|
+
import clientnode from 'clientnode';
|
|
3
3
|
export declare let loadedConfiguration: null | ResolvedConfiguration;
|
|
4
|
-
export declare const log: Logger;
|
|
4
|
+
export declare const log: clientnode.Logger;
|
|
5
5
|
/**
|
|
6
6
|
* Main entry point to determine current configuration.
|
|
7
7
|
* @param context - Location from where to build current application.
|
package/configurator.js
CHANGED
|
@@ -20,13 +20,35 @@ import "core-js/modules/es.iterator.constructor.js";
|
|
|
20
20
|
import "core-js/modules/es.iterator.filter.js";
|
|
21
21
|
import "core-js/modules/es.iterator.map.js";
|
|
22
22
|
import "core-js/modules/es.json.parse.js";
|
|
23
|
-
import
|
|
23
|
+
import clientnode from 'clientnode';
|
|
24
|
+
const {
|
|
25
|
+
convertCircularObjectToJSON,
|
|
26
|
+
copy,
|
|
27
|
+
currentRequire,
|
|
28
|
+
evaluateDynamicData,
|
|
29
|
+
extend,
|
|
30
|
+
getUTCTimestamp,
|
|
31
|
+
isFileSync,
|
|
32
|
+
isObject,
|
|
33
|
+
isolatedRequire,
|
|
34
|
+
isPlainObject,
|
|
35
|
+
Logger,
|
|
36
|
+
MAXIMAL_NUMBER_OF_ITERATIONS,
|
|
37
|
+
modifyObject,
|
|
38
|
+
optionalRequire,
|
|
39
|
+
parseEncodedObject,
|
|
40
|
+
removeKeyPrefixes,
|
|
41
|
+
UTILITY_SCOPE
|
|
42
|
+
} = clientnode;
|
|
24
43
|
import fileSystem, { lstatSync, readFileSync, unlinkSync } from 'fs';
|
|
25
44
|
import path, { basename, dirname, join, resolve } from 'path';
|
|
26
|
-
import { determineAssetType, determineModuleFilePath, determineModuleLocations, resolveAutoInjection, resolveBuildConfigurationFilePaths, resolveModulesInFolders, normalizeGivenInjection, normalizePaths } from
|
|
27
|
-
import packageConfiguration
|
|
28
|
-
import {
|
|
45
|
+
import { determineAssetType, determineModuleFilePath, determineModuleLocations, resolveAutoInjection, resolveBuildConfigurationFilePaths, resolveModulesInFolders, normalizeGivenInjection, normalizePaths } from "./helper.js";
|
|
46
|
+
import packageConfiguration from './package.json' with { type: 'json' };
|
|
47
|
+
import { SubConfigurationTypes } from "./type.js";
|
|
29
48
|
// endregion
|
|
49
|
+
const {
|
|
50
|
+
configuration: metaConfiguration
|
|
51
|
+
} = packageConfiguration;
|
|
30
52
|
export let loadedConfiguration = null;
|
|
31
53
|
export const log = new Logger({
|
|
32
54
|
name: 'weboptimizer.configurator'
|
package/ejsLoader.js
CHANGED
|
@@ -24,9 +24,9 @@ import { readFileSync } from 'fs';
|
|
|
24
24
|
import { minify as minifyHTML } from 'html-minifier';
|
|
25
25
|
import { extname } from 'path';
|
|
26
26
|
import { LoaderContext } from 'webpack';
|
|
27
|
-
import getConfiguration from
|
|
28
|
-
import { determineModuleFilePath } from
|
|
29
|
-
import { Extensions, Replacements, ResolvedConfiguration } from
|
|
27
|
+
import getConfiguration from "./configurator.js";
|
|
28
|
+
import { determineModuleFilePath } from "./helper.js";
|
|
29
|
+
import { Extensions, Replacements, ResolvedConfiguration } from "./type.js";
|
|
30
30
|
// endregion
|
|
31
31
|
// region types
|
|
32
32
|
|
package/helper.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Encoding,
|
|
2
|
-
import { BuildConfiguration, Extensions, GivenInjection, GivenInjectionConfiguration, NormalizedGivenInjection, PathConfiguration, PackageDescriptor, Replacements, ResolvedBuildConfiguration, SpecificExtensions } from './type';
|
|
1
|
+
import type { Encoding, Mapping } from 'clientnode';
|
|
2
|
+
import type { BuildConfiguration, Extensions, GivenInjection, GivenInjectionConfiguration, NormalizedGivenInjection, PathConfiguration, PackageDescriptor, Replacements, ResolvedBuildConfiguration, SpecificExtensions } from './type';
|
|
3
|
+
import clientnode from 'clientnode';
|
|
3
4
|
export declare const KNOWN_FILE_EXTENSIONS: Array<string>;
|
|
4
|
-
export declare const log: Logger;
|
|
5
|
+
export declare const log: clientnode.Logger;
|
|
5
6
|
/**
|
|
6
7
|
* Determines whether given file path is within given list of file locations.
|
|
7
8
|
* @param filePath - Path to file to check.
|
package/helper.js
CHANGED
|
@@ -27,10 +27,22 @@ import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
|
27
27
|
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
28
28
|
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
29
29
|
import "core-js/modules/es.set.union.v2.js";
|
|
30
|
-
import
|
|
30
|
+
import clientnode from 'clientnode';
|
|
31
|
+
const {
|
|
32
|
+
copy,
|
|
33
|
+
currentRequire,
|
|
34
|
+
escapeRegularExpressions,
|
|
35
|
+
extend,
|
|
36
|
+
isAnyMatching,
|
|
37
|
+
isDirectorySync,
|
|
38
|
+
isFileSync,
|
|
39
|
+
isPlainObject,
|
|
40
|
+
Logger,
|
|
41
|
+
represent,
|
|
42
|
+
walkDirectoryRecursivelySync
|
|
43
|
+
} = clientnode;
|
|
31
44
|
import { existsSync, readFileSync } from 'fs';
|
|
32
45
|
import { basename, dirname, extname, join, normalize, resolve, sep, relative } from 'path';
|
|
33
|
-
import { BuildConfiguration, Extensions, GivenInjection, GivenInjectionConfiguration, NormalizedGivenInjection, PathConfiguration, PackageConfiguration, PackageDescriptor, Replacements, ResolvedBuildConfiguration, ResolvedBuildConfigurationItem, SpecificExtensions } from './type';
|
|
34
46
|
// endregion
|
|
35
47
|
// region constants
|
|
36
48
|
export const KNOWN_FILE_EXTENSIONS = ['js', 'ts', 'json', 'css', 'eot', 'gif', 'html', 'ico', 'jpg', 'png', 'ejs', 'svg', 'ttf', 'woff', '.woff2'];
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env babel-node
|
|
2
|
-
import
|
|
3
|
-
export declare const log: Logger;
|
|
2
|
+
import clientnode from 'clientnode';
|
|
3
|
+
export declare const log: clientnode.Logger;
|
|
4
4
|
/**
|
|
5
5
|
* Main entry point.
|
|
6
6
|
* @param context - Location from where to build current application.
|
package/index.js
CHANGED
|
@@ -23,16 +23,33 @@ import "core-js/modules/es.iterator.constructor.js";
|
|
|
23
23
|
import "core-js/modules/es.iterator.filter.js";
|
|
24
24
|
import "core-js/modules/es.iterator.map.js";
|
|
25
25
|
import "core-js/modules/es.json.stringify.js";
|
|
26
|
-
import {
|
|
27
|
-
import
|
|
26
|
+
import { exec as execChildProcess, spawn as spawnChildProcess } from 'child_process';
|
|
27
|
+
import clientnode from 'clientnode';
|
|
28
|
+
const {
|
|
29
|
+
CLOSE_EVENT_NAMES,
|
|
30
|
+
copyDirectoryRecursiveSync,
|
|
31
|
+
copyFileSync,
|
|
32
|
+
evaluate,
|
|
33
|
+
getProcessCloseHandler,
|
|
34
|
+
handleChildProcess,
|
|
35
|
+
isDirectory,
|
|
36
|
+
isDirectorySync,
|
|
37
|
+
isFile,
|
|
38
|
+
isFileSync,
|
|
39
|
+
isPlainObject,
|
|
40
|
+
Logger,
|
|
41
|
+
MAXIMAL_NUMBER_OF_ITERATIONS,
|
|
42
|
+
NOOP,
|
|
43
|
+
parseEncodedObject,
|
|
44
|
+
walkDirectoryRecursively
|
|
45
|
+
} = clientnode;
|
|
28
46
|
import { chmodSync, unlinkSync } from 'fs';
|
|
29
47
|
import { writeFile, unlink } from 'fs/promises';
|
|
30
|
-
import
|
|
48
|
+
import globAll from 'glob-all';
|
|
31
49
|
import path, { join, resolve } from 'path';
|
|
32
50
|
import { rimraf as removeDirectoryRecursively, sync as removeDirectoryRecursivelySync } from 'rimraf';
|
|
33
|
-
import { load as loadConfiguration } from
|
|
34
|
-
import { determineAssetType, determineModuleFilePath, determineModuleLocations, isFilePathInLocation, renderFilePathTemplate, resolveBuildConfigurationFilePaths, stripLoader } from
|
|
35
|
-
import { Command, CommandLineArguments, GivenInjection, ResolvedBuildConfiguration, ResolvedBuildConfigurationItem, ResolvedConfiguration } from './type';
|
|
51
|
+
import { load as loadConfiguration } from "./configurator.js";
|
|
52
|
+
import { determineAssetType, determineModuleFilePath, determineModuleLocations, isFilePathInLocation, renderFilePathTemplate, resolveBuildConfigurationFilePaths, stripLoader } from "./helper.js";
|
|
36
53
|
// endregion
|
|
37
54
|
export const log = new Logger({
|
|
38
55
|
name: 'weboptimizer'
|
|
@@ -135,7 +152,7 @@ environment = eval('process.env')) => {
|
|
|
135
152
|
for (const filePath of configuration.path.tidyUpOnClear) if (filePath) if (isFileSync(filePath))
|
|
136
153
|
// NOTE: Close handler have to be synchronous.
|
|
137
154
|
unlinkSync(filePath);else if (isDirectorySync(filePath)) removeDirectoryRecursivelySync(filePath);
|
|
138
|
-
removeDirectoryRecursivelySync(
|
|
155
|
+
removeDirectoryRecursivelySync(globAll.sync(configuration.path.tidyUpOnClearGlobs));
|
|
139
156
|
}
|
|
140
157
|
// endregion
|
|
141
158
|
// region handle build
|
|
@@ -169,7 +186,7 @@ environment = eval('process.env')) => {
|
|
|
169
186
|
for (const filePath of configuration.path.tidyUp) if (filePath) if (isFileSync(filePath))
|
|
170
187
|
// NOTE: Close handler have to be synchronous.
|
|
171
188
|
unlinkSync(filePath);else if (isDirectorySync(filePath)) removeDirectoryRecursivelySync(filePath);
|
|
172
|
-
removeDirectoryRecursivelySync(
|
|
189
|
+
removeDirectoryRecursivelySync(globAll.sync(configuration.path.tidyUpGlobs));
|
|
173
190
|
};
|
|
174
191
|
closeEventHandlers.push(tidyUp);
|
|
175
192
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -88,12 +88,15 @@
|
|
|
88
88
|
"@babel/core": "^8.0.1",
|
|
89
89
|
"@babel/plugin-proposal-decorators": "^8.0.2",
|
|
90
90
|
"@babel/plugin-transform-class-properties": "^8.0.1",
|
|
91
|
+
"@babel/plugin-transform-proto-to-assign": "^8.0.1",
|
|
91
92
|
"@babel/preset-env": "^8.0.2",
|
|
92
93
|
"@babel/preset-typescript": "^8.0.1",
|
|
93
94
|
"babel-loader": "^10.1.1",
|
|
94
95
|
"babel-plugin-polyfill-corejs3": "^1.0.0",
|
|
96
|
+
"babel-plugin-transform-rewrite-imports": "^1.5.4",
|
|
95
97
|
"babel-preset-minify": "^0.5.2",
|
|
96
98
|
"clientnode": "4.0.1428",
|
|
99
|
+
"core-js": "^3.49.0",
|
|
97
100
|
"ejs": "^6.0.1",
|
|
98
101
|
"exports-loader": "^5.0.0",
|
|
99
102
|
"extract-loader": "^5.1.0",
|
|
@@ -1208,7 +1211,7 @@
|
|
|
1208
1211
|
],
|
|
1209
1212
|
"presets": {
|
|
1210
1213
|
"#": "NOTE: We have to disable module export/import transformation to allow tree shaking by the final (minimizer).",
|
|
1211
|
-
"__evaluate__": "[['@babel/preset-env', {
|
|
1214
|
+
"__evaluate__": "[['@babel/preset-env', {targets: self.generic.isWeb ? {browsers: self.generic.supportedBrowsers, node: packageConfiguration.engines.node.replace(/>?=?([0-9]+)/, '$1')} : {node: packageConfiguration.engines.node.replace(/>?=?([0-9]+)/, '$1')}}], '@babel/preset-typescript'].concat((self.debug || !self.module.optimizer.babelMinify.module || 2 < self.givenCommandLineArguments.length && self.givenCommandLineArguments[2] === 'document') ? [] : [['minify', self.module.optimizer.babelMinify.module]])"
|
|
1212
1215
|
}
|
|
1213
1216
|
},
|
|
1214
1217
|
"regularExpression": "\\.[jt]sx?(?:\\?.*)?$"
|
|
@@ -24,8 +24,8 @@ import { copy, extend, Mapping } from 'clientnode';
|
|
|
24
24
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
25
25
|
import { JSDOM as DOM } from 'jsdom';
|
|
26
26
|
import { Compilation, Compiler, LoaderContext } from 'webpack';
|
|
27
|
-
import ejsLoader, { LoaderConfiguration as EJSLoaderConfiguration } from
|
|
28
|
-
import { HTMLTransformationOptions, HTMLWebpackPluginBeforeEmitData, WebpackLoader } from
|
|
27
|
+
import ejsLoader, { LoaderConfiguration as EJSLoaderConfiguration } from "../ejsLoader.js";
|
|
28
|
+
import { HTMLTransformationOptions, HTMLWebpackPluginBeforeEmitData, WebpackLoader } from "../type.js";
|
|
29
29
|
// endregion
|
|
30
30
|
|
|
31
31
|
export class HTMLTransformation {
|
|
@@ -25,7 +25,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
25
25
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
26
|
import { Compilation, Compiler } from 'webpack';
|
|
27
27
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
28
|
-
import { InPlaceAssetConfiguration, InPlaceAssetsIntoHTMLOptions, WebpackAssets, WebpackBaseAssets } from
|
|
28
|
+
import { InPlaceAssetConfiguration, InPlaceAssetsIntoHTMLOptions, WebpackAssets, WebpackBaseAssets } from "../type.js";
|
|
29
29
|
// endregion
|
|
30
30
|
|
|
31
31
|
export class InPlaceAssetsIntoHTML {
|
package/stylelintConfigurator.js
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
import getConfiguration from
|
|
20
|
-
import { ResolvedConfiguration } from
|
|
19
|
+
import getConfiguration from "./configurator.js";
|
|
20
|
+
import { ResolvedConfiguration } from "./type.js";
|
|
21
21
|
// endregion
|
|
22
22
|
const configuration = getConfiguration();
|
|
23
23
|
module.exports = configuration.stylelint;
|
package/type.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AnyFunction, Encoding, Mapping, PlainObject, SecondParameter } from 'clientnode';
|
|
1
|
+
import type { AnyFunction, Encoding, Mapping, PlainObject, SecondParameter } from 'clientnode';
|
|
2
2
|
import type FaviconWebpackPlugin from 'favicons-webpack-plugin';
|
|
3
|
-
import { FaviconWebpackPlugionOptions as FaviconWebpackPluginOptions } from 'favicons-webpack-plugin/src/options';
|
|
4
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
3
|
+
import type { FaviconWebpackPlugionOptions as FaviconWebpackPluginOptions } from 'favicons-webpack-plugin/src/options';
|
|
4
|
+
import type HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
5
|
import type ImageMinimizerWebpackPlugin from 'image-minimizer-webpack-plugin';
|
|
6
|
-
import { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
7
|
-
import { JSDOM } from 'jsdom';
|
|
6
|
+
import type { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
7
|
+
import type { JSDOM } from 'jsdom';
|
|
8
8
|
import type MiniCSSExtractPlugin from 'mini-css-extract-plugin';
|
|
9
9
|
import type TerserWebpackPlugin from 'terser-webpack-plugin';
|
|
10
|
-
import { DefinePlugin as WebpackDefinePlugin, Configuration as BaseWebpackConfiguration, IgnorePlugin as WebpackIgnorePlugin, library as webpackLibrary, ModuleOptions as WebpackModuleOptions, RuleSetRule as WebpackRuleSetRule, RuleSetUseItem as WebpackRuleSetUseItem, WebpackOptionsNormalized } from 'webpack';
|
|
11
|
-
import { WebpackPartial as WorkboxBaseCommonOptions, BasePartial as WorkboxCommonOptions, WebpackGenerateSWOptions as WorkboxGenerateSWOptions, WebpackInjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
10
|
+
import type { DefinePlugin as WebpackDefinePlugin, Configuration as BaseWebpackConfiguration, IgnorePlugin as WebpackIgnorePlugin, library as webpackLibrary, ModuleOptions as WebpackModuleOptions, RuleSetRule as WebpackRuleSetRule, RuleSetUseItem as WebpackRuleSetUseItem, WebpackOptionsNormalized } from 'webpack';
|
|
11
|
+
import type { WebpackPartial as WorkboxBaseCommonOptions, BasePartial as WorkboxCommonOptions, WebpackGenerateSWOptions as WorkboxGenerateSWOptions, WebpackInjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
12
12
|
import type OfflinePlugin from 'workbox-webpack-plugin';
|
|
13
13
|
export interface Browser {
|
|
14
14
|
debug: boolean;
|
package/type.js
CHANGED
|
@@ -16,31 +16,18 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
import { AnyFunction, Encoding, Mapping, PlainObject, SecondParameter } from 'clientnode';
|
|
20
|
-
import { FaviconWebpackPlugionOptions as FaviconWebpackPluginOptions } from 'favicons-webpack-plugin/src/options';
|
|
21
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
22
|
-
import { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
23
|
-
import { JSDOM } from 'jsdom';
|
|
24
|
-
import { DefinePlugin as WebpackDefinePlugin, Configuration as BaseWebpackConfiguration, IgnorePlugin as WebpackIgnorePlugin, library as webpackLibrary, ModuleOptions as WebpackModuleOptions, RuleSetRule as WebpackRuleSetRule, RuleSetUseItem as WebpackRuleSetUseItem, WebpackOptionsNormalized } from 'webpack';
|
|
25
|
-
import { WebpackPartial as WorkboxBaseCommonOptions, BasePartial as WorkboxCommonOptions, WebpackGenerateSWOptions as WorkboxGenerateSWOptions, WebpackInjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
26
|
-
|
|
27
19
|
// endregion
|
|
28
20
|
// region exports
|
|
29
21
|
/// region generic
|
|
30
|
-
|
|
31
22
|
/// endregion
|
|
32
23
|
/// region injection
|
|
33
|
-
|
|
34
24
|
/// endregion
|
|
35
25
|
/// region configuration
|
|
36
26
|
// region plugins
|
|
37
|
-
|
|
38
27
|
// endregion
|
|
39
28
|
//// region path
|
|
40
|
-
|
|
41
29
|
//// endregion
|
|
42
30
|
//// region build
|
|
43
|
-
|
|
44
31
|
export const SubConfigurationTypes = ['debug', 'document', 'test', 'test:browser'];
|
|
45
32
|
export const TaskTypes = ['build', 'serve', ...SubConfigurationTypes];
|
|
46
33
|
//// endregion
|
package/webpackConfigurator.js
CHANGED
|
@@ -16,11 +16,68 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
+
const _rewrite = (specifier, options) => {
|
|
20
|
+
if (typeof specifier !== 'string') {
|
|
21
|
+
throw new TypeError(`rewrite error: expected specifier of type string, not ${typeof specifier}`);
|
|
22
|
+
}
|
|
23
|
+
let replacementMap;
|
|
24
|
+
if (options.replaceExtensions) {
|
|
25
|
+
Object.entries(options.replaceExtensions).some(([target, replacement]) => {
|
|
26
|
+
if (target.startsWith('^') || target.endsWith('$')) {
|
|
27
|
+
const targetRegExp = new RegExp(target);
|
|
28
|
+
const capturingGroups = Array.from(specifier.match(targetRegExp) || []);
|
|
29
|
+
if (capturingGroups.length) {
|
|
30
|
+
replacementMap = [targetRegExp, replacement, capturingGroups];
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
} else if (specifier.endsWith(target)) {
|
|
34
|
+
replacementMap = [target, replacement, []];
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
let finalImportPath = specifier;
|
|
40
|
+
if (replacementMap) {
|
|
41
|
+
const [target, replacement, capturingGroups] = replacementMap;
|
|
42
|
+
finalImportPath = finalImportPath.replace(target, typeof replacement === 'string' ? replacement : replacement({
|
|
43
|
+
specifier,
|
|
44
|
+
capturingGroups,
|
|
45
|
+
filepath: '/__w/weboptimizer/weboptimizer/webpackConfigurator.ts'
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
const isRelative = finalImportPath.startsWith('./') || finalImportPath.startsWith('.\\') || finalImportPath.startsWith('../') || finalImportPath.startsWith('..\\') || finalImportPath === '.' || finalImportPath === '..';
|
|
49
|
+
if (options.appendExtension && isRelative) {
|
|
50
|
+
const endsWithSlash = /(\/|\\)$/.test(finalImportPath);
|
|
51
|
+
const basenameIsDots = /(^\.?\.(\/|\\)?$)|((\/|\\)\.?\.(\/|\\)?$)/.test(finalImportPath);
|
|
52
|
+
const extensionToAppend = typeof options.appendExtension === 'string' ? options.appendExtension : options.appendExtension({
|
|
53
|
+
specifier,
|
|
54
|
+
capturingGroups: [],
|
|
55
|
+
filepath: '/__w/weboptimizer/weboptimizer/webpackConfigurator.ts'
|
|
56
|
+
});
|
|
57
|
+
if (extensionToAppend !== undefined) {
|
|
58
|
+
if (basenameIsDots) {
|
|
59
|
+
finalImportPath += `${endsWithSlash ? '' : '/'}index${extensionToAppend}`;
|
|
60
|
+
} else {
|
|
61
|
+
const hasRecognizedExtension = !endsWithSlash && options.recognizedExtensions.some(extension => {
|
|
62
|
+
return finalImportPath.endsWith(extension);
|
|
63
|
+
});
|
|
64
|
+
if (!hasRecognizedExtension) {
|
|
65
|
+
finalImportPath = endsWithSlash ? finalImportPath + `index${extensionToAppend}` : finalImportPath + extensionToAppend;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return finalImportPath;
|
|
71
|
+
},
|
|
72
|
+
_rewrite_options = {
|
|
73
|
+
"appendExtension": ".js",
|
|
74
|
+
"recognizedExtensions": [".js", ".jsx", ".d.ts", ".ts", ".tsx", ".json"]
|
|
75
|
+
};
|
|
19
76
|
import "core-js/modules/es.array.push.js";
|
|
20
|
-
import "core-js/modules/es.array.unshift.js";
|
|
21
77
|
import "core-js/modules/es.iterator.constructor.js";
|
|
22
78
|
import "core-js/modules/es.iterator.filter.js";
|
|
23
79
|
import "core-js/modules/es.iterator.map.js";
|
|
80
|
+
import "core-js/modules/es.iterator.some.js";
|
|
24
81
|
import { convertToValidVariableName, evaluate, EvaluationResult, escapeRegularExpressions, extend, isFileSync, isObject, isPlainObject, Logger, Mapping, mask, PlainObject, PositiveEvaluationResult, RecursivePartial, represent, Unpacked } from 'clientnode';
|
|
25
82
|
import { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
26
83
|
import { extname, join, relative, resolve } from 'path';
|
|
@@ -30,12 +87,12 @@ import util from 'util';
|
|
|
30
87
|
import { Chunk, Compiler, Compilation, ContextReplacementPlugin, DefinePlugin, HotModuleReplacementPlugin, IgnorePlugin, NormalModuleReplacementPlugin, ProvidePlugin, RuleSetRule } from 'webpack';
|
|
31
88
|
import { RawSource as WebpackRawSource } from 'webpack-sources';
|
|
32
89
|
import { InjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
33
|
-
import getConfiguration from
|
|
34
|
-
import { LoaderConfiguration as EJSLoaderConfiguration } from
|
|
35
|
-
import { determineAssetType, determineExternalRequest, determineModuleFilePath, getClosestPackageDescriptor, isFilePathInLocation, normalizePaths, stripLoader } from
|
|
36
|
-
import InPlaceAssetsIntoHTML from
|
|
37
|
-
import HTMLTransformation from
|
|
38
|
-
import { AdditionalLoaderConfiguration, AssetPathConfiguration, EvaluationScope, GenericLoader, HTMLConfiguration, IgnorePattern, InPlaceConfiguration, Loader, PackageDescriptor, RedundantRequest, ResolvedConfiguration, RuleSet, WebpackConfiguration, WebpackExtendedResolveData, WebpackLoader, WebpackLoaderConfiguration, WebpackLoaderIndicator, WebpackPlugin, WebpackPlugins, WebpackResolveData } from
|
|
90
|
+
import getConfiguration from "./configurator.js";
|
|
91
|
+
import { LoaderConfiguration as EJSLoaderConfiguration } from "./ejsLoader.js";
|
|
92
|
+
import { determineAssetType, determineExternalRequest, determineModuleFilePath, getClosestPackageDescriptor, isFilePathInLocation, normalizePaths, stripLoader } from "./helper.js";
|
|
93
|
+
import InPlaceAssetsIntoHTML from "./plugins/InPlaceAssetsIntoHTML.js";
|
|
94
|
+
import HTMLTransformation from "./plugins/HTMLTransformation.js";
|
|
95
|
+
import { AdditionalLoaderConfiguration, AssetPathConfiguration, EvaluationScope, GenericLoader, HTMLConfiguration, IgnorePattern, InPlaceConfiguration, Loader, PackageDescriptor, RedundantRequest, ResolvedConfiguration, RuleSet, WebpackConfiguration, WebpackExtendedResolveData, WebpackLoader, WebpackLoaderConfiguration, WebpackLoaderIndicator, WebpackPlugin, WebpackPlugins, WebpackResolveData } from "./type.js";
|
|
39
96
|
export const log = new Logger({
|
|
40
97
|
name: 'weboptimizer.webpack-configurator'
|
|
41
98
|
});
|
|
@@ -828,7 +885,7 @@ if (!module.optimizer.minimizer) {
|
|
|
828
885
|
// region configuration
|
|
829
886
|
let customConfiguration = {};
|
|
830
887
|
if (configuration.path.configuration.json) try {
|
|
831
|
-
require.resolve(configuration.path.configuration.json);
|
|
888
|
+
require.resolve(_rewrite(configuration.path.configuration.json, _rewrite_options));
|
|
832
889
|
try {
|
|
833
890
|
customConfiguration = currentRequire(configuration.path.configuration.json);
|
|
834
891
|
} catch (error) {
|
|
@@ -941,7 +998,7 @@ if (!Array.isArray(module.skipParseRegularExpressions) || module.skipParseRegula
|
|
|
941
998
|
noParse: module.skipParseRegularExpressions
|
|
942
999
|
};
|
|
943
1000
|
if (configuration.path.configuration.javaScript) try {
|
|
944
|
-
require.resolve(configuration.path.configuration.javaScript);
|
|
1001
|
+
require.resolve(_rewrite(configuration.path.configuration.javaScript, _rewrite_options));
|
|
945
1002
|
const result = optionalRequire(configuration.path.configuration.javaScript);
|
|
946
1003
|
if (isPlainObject(result)) {
|
|
947
1004
|
if (Object.prototype.hasOwnProperty.call(result, 'replaceWebOptimizer')) webpackConfiguration = result.replaceWebOptimizer;else extend(true, webpackConfiguration, result);
|