weboptimizer 4.0.21 → 4.0.22
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/configurator.js +0 -1
- package/ejsLoader.d.ts +1 -1
- package/ejsLoader.js +6 -5
- package/helper.js +14 -1
- package/index.js +6 -1
- package/package.json +48 -32
- package/type.d.ts +2 -7
- package/webpackConfigurator.js +28 -3
package/configurator.js
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
// region imports
|
|
19
19
|
import { convertCircularObjectToJSON, copy, evaluateAsyncDynamicData, evaluateDynamicData, extend, getUTCTimestamp, importsPromise, isFileSync, isObject, isPlainObject, Logger, MAXIMAL_NUMBER_OF_ITERATIONS, modifyObject, optionalImport, parseEncodedObject, removeKeyPrefixes, UTILITY_SCOPE } from 'clientnode';
|
|
20
20
|
import fileSystem, { lstatSync, readFileSync, unlinkSync } from 'fs';
|
|
21
|
-
import { createRequire } from 'node:module';
|
|
22
21
|
import path, { basename, dirname, join, resolve } from 'path';
|
|
23
22
|
import { determineAssetType, determineModuleFilePath, determineModuleLocations, resolveAutoInjection, resolveBuildConfigurationFilePaths, resolveModulesInFolders, normalizeGivenInjection, normalizePaths } from "./helper.js";
|
|
24
23
|
import packageConfiguration from './package.json' with { type: 'json' };
|
package/ejsLoader.d.ts
CHANGED
package/ejsLoader.js
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
*/
|
|
18
18
|
// region
|
|
19
19
|
import { transform as babelTransform } from '@babel/core';
|
|
20
|
-
import babelMinifyPreset from 'babel-preset-minify';
|
|
21
20
|
import { convertSubstringInPlainObject, copy, evaluate, extend, Logger, UTILITY_SCOPE } from 'clientnode';
|
|
22
21
|
import ejs from 'ejs';
|
|
23
22
|
import { readFile } from 'fs/promises';
|
|
@@ -48,12 +47,15 @@ export const loader = async function (source) {
|
|
|
48
47
|
compileSteps: 2,
|
|
49
48
|
compress: {
|
|
50
49
|
html: {},
|
|
51
|
-
javaScript:
|
|
50
|
+
javaScript: true
|
|
52
51
|
},
|
|
53
52
|
context: './',
|
|
54
53
|
debug: false,
|
|
55
54
|
extensions: {
|
|
56
55
|
file: {
|
|
56
|
+
alias: {
|
|
57
|
+
'.js': ['.js', '.ts', '.tsx', '.jsx']
|
|
58
|
+
},
|
|
57
59
|
external: [],
|
|
58
60
|
internal: ['.js', '.json', '.css', '.svg', '.png', '.jpg', '.gif', '.ico', '.html', '.eot', '.ttf', '.woff', '.woff2']
|
|
59
61
|
}
|
|
@@ -243,10 +245,9 @@ export const loader = async function (source) {
|
|
|
243
245
|
ast: false,
|
|
244
246
|
babelrc: false,
|
|
245
247
|
comments: !givenOptions.compress?.javaScript,
|
|
246
|
-
compact: Boolean(givenOptions.compress?.javaScript),
|
|
247
248
|
filename: options.filename || 'unknown',
|
|
248
|
-
minified:
|
|
249
|
-
presets:
|
|
249
|
+
minified: givenOptions.compress?.javaScript,
|
|
250
|
+
presets: [],
|
|
250
251
|
sourceMaps: false,
|
|
251
252
|
sourceType: 'script'
|
|
252
253
|
}, (error, file) => {
|
package/helper.js
CHANGED
|
@@ -154,6 +154,9 @@ export const applyContext = (request, context = './', referencePath = './', alia
|
|
|
154
154
|
*/
|
|
155
155
|
export const determineExternalRequest = (request, context = './', requestContext = './', normalizedGivenInjection = {}, relativeExternalModuleLocations = ['node_modules'], aliases = {}, moduleReplacements = {}, extensions = {
|
|
156
156
|
file: {
|
|
157
|
+
alias: {
|
|
158
|
+
'.js': ['.js', '.ts', '.tsx', '.jsx']
|
|
159
|
+
},
|
|
157
160
|
external: ['.compiled.js', '.js', '.json'],
|
|
158
161
|
internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
159
162
|
}
|
|
@@ -374,6 +377,9 @@ export const normalizeGivenInjection = givenInjection => {
|
|
|
374
377
|
*/
|
|
375
378
|
export const resolveAutoInjection = (givenInjection, buildConfigurations, aliases = {}, moduleReplacements = {}, extensions = {
|
|
376
379
|
file: {
|
|
380
|
+
alias: {
|
|
381
|
+
'.js': ['.js', '.ts', '.tsx', '.jsx']
|
|
382
|
+
},
|
|
377
383
|
external: ['compiled.js', '.js', '.json'],
|
|
378
384
|
internal: KNOWN_FILE_EXTENSIONS.map(suffix => `.${suffix}`)
|
|
379
385
|
}
|
|
@@ -591,7 +597,14 @@ export const findPackageDescriptorFilePath = (start, fileName = 'package.json')
|
|
|
591
597
|
export const getClosestPackageDescriptor = async (modulePath, fileName = 'package.json') => {
|
|
592
598
|
const filePath = findPackageDescriptorFilePath(modulePath, fileName);
|
|
593
599
|
if (!filePath) return null;
|
|
594
|
-
|
|
600
|
+
|
|
601
|
+
/*
|
|
602
|
+
NOTE: In native ecmascript module contexts json imports are wrapped
|
|
603
|
+
into a module namespace object providing its content as "default"
|
|
604
|
+
export whereas commonjs interoperability provides it directly.
|
|
605
|
+
*/
|
|
606
|
+
const importedModule = await import(filePath);
|
|
607
|
+
const configuration = importedModule.default ?? importedModule;
|
|
595
608
|
/*
|
|
596
609
|
If the package.json does not have a name property, try again from
|
|
597
610
|
one level higher.
|
package/index.js
CHANGED
|
@@ -288,7 +288,12 @@ environment = eval('process.env')) => {
|
|
|
288
288
|
}
|
|
289
289
|
// endregion
|
|
290
290
|
} catch (error) {
|
|
291
|
-
if (configuration.debug) throw error;else
|
|
291
|
+
if (configuration.debug) throw error;else {
|
|
292
|
+
log.error(error);
|
|
293
|
+
|
|
294
|
+
// NOTE: Forward nested return codes.
|
|
295
|
+
process.exitCode = error.returnCode ?? 1;
|
|
296
|
+
}
|
|
292
297
|
}
|
|
293
298
|
return clear;
|
|
294
299
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.22",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -94,7 +94,6 @@
|
|
|
94
94
|
"babel-loader": "^10.1.1",
|
|
95
95
|
"babel-plugin-polyfill-corejs3": "^1.0.0",
|
|
96
96
|
"babel-plugin-transform-rewrite-imports": "^1.5.4",
|
|
97
|
-
"babel-preset-minify": "^0.5.2",
|
|
98
97
|
"clientnode": "4.0.1451",
|
|
99
98
|
"core-js": "^3.49.0",
|
|
100
99
|
"ejs": "^6.0.1",
|
|
@@ -583,7 +582,19 @@
|
|
|
583
582
|
},
|
|
584
583
|
"module": {
|
|
585
584
|
"optimizer": {
|
|
586
|
-
"cssnano": null
|
|
585
|
+
"cssnano": null,
|
|
586
|
+
"terser": {
|
|
587
|
+
"terserOptions": {
|
|
588
|
+
"compress": {
|
|
589
|
+
"drop_console": {
|
|
590
|
+
"__evaluate__": "!self.debug"
|
|
591
|
+
},
|
|
592
|
+
"drop_debugger": {
|
|
593
|
+
"__evaluate__": "!self.debug"
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
587
598
|
}
|
|
588
599
|
}
|
|
589
600
|
},
|
|
@@ -601,6 +612,15 @@
|
|
|
601
612
|
},
|
|
602
613
|
"extensions": {
|
|
603
614
|
"file": {
|
|
615
|
+
"#": "NOTE: Maps import specifier extensions to resolvable source extensions (webpack's \"resolve.extensionAlias\") since imports rewritten to \".js\" have to be resolved back to their typescript sources.",
|
|
616
|
+
"alias": {
|
|
617
|
+
".js": [
|
|
618
|
+
".js",
|
|
619
|
+
".ts",
|
|
620
|
+
".tsx",
|
|
621
|
+
".jsx"
|
|
622
|
+
]
|
|
623
|
+
},
|
|
604
624
|
"external": {
|
|
605
625
|
"__evaluate__": "self.generic.isWeb ? self.extensions.file.internal : ['.compiled.js', '.js', '.json', '.mjs']"
|
|
606
626
|
},
|
|
@@ -928,24 +948,6 @@
|
|
|
928
948
|
}
|
|
929
949
|
},
|
|
930
950
|
"optimizer": {
|
|
931
|
-
"babelMinify": {
|
|
932
|
-
"bundle": {
|
|
933
|
-
"transform": {
|
|
934
|
-
"removeConsole": true,
|
|
935
|
-
"removeDebugger": true,
|
|
936
|
-
"mangle": {
|
|
937
|
-
"topLevel": {
|
|
938
|
-
"#": "Indicates to not mangle scope names from the entry (main) scope in libraries.",
|
|
939
|
-
"__evaluate__": "!self.library"
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
},
|
|
944
|
-
"module": {
|
|
945
|
-
"removeConsole": true,
|
|
946
|
-
"removeDebugger": true
|
|
947
|
-
}
|
|
948
|
-
},
|
|
949
951
|
"cssnano": {
|
|
950
952
|
"#": "The autoprefixer has to be disabled in this context since it would remove all needed vendor prefixes from the preceding processing (every prefix should be needed here).",
|
|
951
953
|
"preset": [
|
|
@@ -1065,7 +1067,19 @@
|
|
|
1065
1067
|
},
|
|
1066
1068
|
"loader": []
|
|
1067
1069
|
},
|
|
1068
|
-
"
|
|
1070
|
+
"terser": {
|
|
1071
|
+
"terserOptions": {
|
|
1072
|
+
"compress": {
|
|
1073
|
+
"#": "To provide a logging output we need to exclude this feature.",
|
|
1074
|
+
"drop_console": {
|
|
1075
|
+
"__evaluate__": "!self.debug"
|
|
1076
|
+
},
|
|
1077
|
+
"drop_debugger": {
|
|
1078
|
+
"__evaluate__": "!self.debug"
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1069
1083
|
},
|
|
1070
1084
|
"preprocessor": {
|
|
1071
1085
|
"cascadingStyleSheet": {
|
|
@@ -1113,7 +1127,7 @@
|
|
|
1113
1127
|
"__evaluate__": "self.module.optimizer.htmlMinifier"
|
|
1114
1128
|
},
|
|
1115
1129
|
"javaScript": {
|
|
1116
|
-
"__evaluate__": "self.
|
|
1130
|
+
"__evaluate__": "!self.debug"
|
|
1117
1131
|
}
|
|
1118
1132
|
},
|
|
1119
1133
|
"context": {
|
|
@@ -1218,8 +1232,8 @@
|
|
|
1218
1232
|
]
|
|
1219
1233
|
],
|
|
1220
1234
|
"presets": {
|
|
1221
|
-
"#": "NOTE: We
|
|
1222
|
-
"__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']
|
|
1235
|
+
"#": "NOTE: We disable module export/import transformation to allow tree shaking by the final (minimizer).",
|
|
1236
|
+
"__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']"
|
|
1223
1237
|
}
|
|
1224
1238
|
},
|
|
1225
1239
|
"regularExpression": "\\.[jt]sx?(?:\\?.*)?$"
|
|
@@ -1492,14 +1506,16 @@
|
|
|
1492
1506
|
},
|
|
1493
1507
|
"module": {
|
|
1494
1508
|
"optimizer": {
|
|
1495
|
-
"
|
|
1496
|
-
"
|
|
1497
|
-
"
|
|
1498
|
-
"
|
|
1509
|
+
"terser": {
|
|
1510
|
+
"terserOptions": {
|
|
1511
|
+
"compress": {
|
|
1512
|
+
"drop_console": {
|
|
1513
|
+
"__evaluate__": "false"
|
|
1514
|
+
},
|
|
1515
|
+
"drop_debugger": {
|
|
1516
|
+
"__evaluate__": "false"
|
|
1517
|
+
}
|
|
1499
1518
|
}
|
|
1500
|
-
},
|
|
1501
|
-
"module": {
|
|
1502
|
-
"removeConsole": false
|
|
1503
1519
|
}
|
|
1504
1520
|
}
|
|
1505
1521
|
}
|
package/type.d.ts
CHANGED
|
@@ -231,6 +231,7 @@ export interface ResolvedBuildConfigurationItem extends BuildConfigurationItem {
|
|
|
231
231
|
}
|
|
232
232
|
export interface Extensions {
|
|
233
233
|
file: {
|
|
234
|
+
alias: Mapping<Array<string>>;
|
|
234
235
|
external: Array<string>;
|
|
235
236
|
internal: Array<string>;
|
|
236
237
|
};
|
|
@@ -325,13 +326,6 @@ export interface ResolvedConfiguration {
|
|
|
325
326
|
filePaths: Array<string>;
|
|
326
327
|
};
|
|
327
328
|
optimizer: BaseWebpackConfiguration['optimization'] & {
|
|
328
|
-
babelMinify?: {
|
|
329
|
-
bundle?: {
|
|
330
|
-
plugin?: PlainObject;
|
|
331
|
-
transform?: PlainObject;
|
|
332
|
-
};
|
|
333
|
-
module?: PlainObject;
|
|
334
|
-
};
|
|
335
329
|
cssnano?: PlainObject;
|
|
336
330
|
data: ResourceLoaderConfiguration;
|
|
337
331
|
font: {
|
|
@@ -346,6 +340,7 @@ export interface ResolvedConfiguration {
|
|
|
346
340
|
exclude: null | string;
|
|
347
341
|
loader: Array<string>;
|
|
348
342
|
};
|
|
343
|
+
terser: Mapping<unknown>;
|
|
349
344
|
};
|
|
350
345
|
preprocessor: {
|
|
351
346
|
cascadingStyleSheet: WebpackLoader & {
|
package/webpackConfigurator.js
CHANGED
|
@@ -737,7 +737,8 @@ if (!module.optimizer.minimizer) {
|
|
|
737
737
|
module.optimizer.minimizer = [];
|
|
738
738
|
if (plugins.Terser) module.optimizer.minimizer.push(new plugins.Terser({
|
|
739
739
|
extractComments: false,
|
|
740
|
-
parallel: true
|
|
740
|
+
parallel: true,
|
|
741
|
+
...module.optimizer.terser
|
|
741
742
|
}));
|
|
742
743
|
if (plugins.ImageMinimizer) module.optimizer.minimizer.push(new plugins.ImageMinimizer(extend(true, {
|
|
743
744
|
minimizer: {
|
|
@@ -765,7 +766,26 @@ export let webpackConfiguration = extend(true, {
|
|
|
765
766
|
devServer: configuration.development.server,
|
|
766
767
|
experiments: {
|
|
767
768
|
futureDefaults: true,
|
|
768
|
-
outputModule: true
|
|
769
|
+
outputModule: true,
|
|
770
|
+
/*
|
|
771
|
+
"futureDefaults" would enable webpack's native css support
|
|
772
|
+
which disables the configured "mini-css-extract-plugin"
|
|
773
|
+
pipeline (naming outputs "<name>.css.css" instead of
|
|
774
|
+
"<name>.compiled.css").
|
|
775
|
+
*/
|
|
776
|
+
css: false,
|
|
777
|
+
/*
|
|
778
|
+
"futureDefaults" would enable webpack's native html support
|
|
779
|
+
which conflicts with the configured ejs / html plugin
|
|
780
|
+
pipeline.
|
|
781
|
+
*/
|
|
782
|
+
html: false,
|
|
783
|
+
/*
|
|
784
|
+
"futureDefaults" would enable webpack's native type stripping
|
|
785
|
+
which cannot handle ".tsx" files; typescript sources are
|
|
786
|
+
transpiled via babel instead.
|
|
787
|
+
*/
|
|
788
|
+
typescript: false
|
|
769
789
|
},
|
|
770
790
|
// region input
|
|
771
791
|
entry: configuration.injection.entry.normalized,
|
|
@@ -773,6 +793,12 @@ export let webpackConfiguration = extend(true, {
|
|
|
773
793
|
resolve: {
|
|
774
794
|
alias: module.aliases,
|
|
775
795
|
aliasFields: configuration.package.aliasPropertyNames,
|
|
796
|
+
/*
|
|
797
|
+
Resolves imports which were rewritten to ".js" (e.g. via
|
|
798
|
+
"babel-plugin-transform-rewrite-imports") back to their
|
|
799
|
+
(typescript) sources.
|
|
800
|
+
*/
|
|
801
|
+
extensionAlias: configuration.extensions.file.alias,
|
|
776
802
|
extensions: configuration.extensions.file.internal,
|
|
777
803
|
mainFields: configuration.package.main.propertyNames,
|
|
778
804
|
mainFiles: configuration.package.main.fileNames,
|
|
@@ -843,7 +869,6 @@ export let webpackConfiguration = extend(true, {
|
|
|
843
869
|
// endregion
|
|
844
870
|
...mask(module.optimizer, {
|
|
845
871
|
exclude: {
|
|
846
|
-
babelMinify: true,
|
|
847
872
|
cssnano: true,
|
|
848
873
|
data: true,
|
|
849
874
|
font: true,
|