uglify-js-minify-css-allfiles 2.6.0 → 2.7.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.
package/README.md CHANGED
@@ -68,6 +68,8 @@ await minifyAll('./src/', {
68
68
  modules: false,
69
69
  useBuiltIns: 'usage',
70
70
  corejs: 3,
71
+ useAppendTransform: true,
72
+ plugins: ['@babel/plugin-proposal-class-properties'],
71
73
  },
72
74
  usePostCSS: {
73
75
  browsers: ['Chrome >= 40'],
@@ -283,7 +285,9 @@ The `useBabel` object supports all @babel/preset-env options:
283
285
  forceAllTransforms: boolean,
284
286
  configPath: string,
285
287
  ignoreBrowserslistConfig: boolean,
286
- shippedProposals: boolean
288
+ shippedProposals: boolean,
289
+ useAppendTransform: boolean,
290
+ plugins: Array<string|Array|Function>
287
291
  }
288
292
  ```
289
293
 
package/demo.js CHANGED
@@ -16,6 +16,8 @@ minifyAll('./test/', {
16
16
  },
17
17
  useBabel: {
18
18
  targets: 'chrome 40',
19
+ useAppendTransform: false,
20
+ plugins: [],
19
21
  },
20
22
  useVersioning: {
21
23
  extensions: ['.png', '.jpg', '.webp', '.avif', '.svg'],
package/dist/module.js CHANGED
@@ -149,6 +149,9 @@ async function updateImageReferences(filePath, versioningOptions, logger, hashMa
149
149
 
150
150
  /**
151
151
  * Resolves Babel options based on the provided configuration.
152
+ * Supports custom plugins through the useBabel.plugins option.
153
+ *
154
+ * @async
152
155
  * @param {boolean|BabelOptions} useBabel - The Babel options object or boolean.
153
156
  * @returns {Promise<BabelOptions|null>} - A promise that resolves to the Babel options or null if disabled.
154
157
  */
@@ -159,11 +162,34 @@ async function resolveBabelOptions(useBabel) {
159
162
  const presetEnvUrl = resolveModulePath('@babel/preset-env');
160
163
  const presetEnv = await import(presetEnvUrl);
161
164
 
162
- return {
163
- presets: [[presetEnv.default, typeof useBabel === 'object' ? useBabel : {}]],
165
+ const options = typeof useBabel === 'object' ? useBabel : {};
166
+ const { useAppendTransform, plugins, ...presetOptions } = options;
167
+
168
+ const babelConfig = {
169
+ presets: [[presetEnv.default, presetOptions]],
170
+ plugins: [],
164
171
  };
172
+
173
+ // Handle custom plugins if provided
174
+ if (plugins && Array.isArray(plugins)) {
175
+ babelConfig.plugins.push(...plugins);
176
+ }
177
+
178
+ // Add appendTransform plugin if useAppendTransform option is enabled
179
+ if (useAppendTransform) {
180
+ try {
181
+ const appendTransformPluginModule = await import('./plugins/append-polyfill-plugin.js');
182
+ const appendTransformPlugin = appendTransformPluginModule.default;
183
+ babelConfig.plugins.push(appendTransformPlugin);
184
+ } catch (pluginError) {
185
+ console.error('Error loading append transform plugin:', pluginError);
186
+ console.error(pluginError.stack);
187
+ }
188
+ }
189
+
190
+ return babelConfig;
165
191
  } catch (error) {
166
- console.error('Error loading @babel/preset-env:', error);
192
+ console.error('Error loading @babel/preset-env or plugins:', error);
167
193
  return null;
168
194
  }
169
195
  }
@@ -283,6 +309,8 @@ async function processFile(filePath, logger, options) {
283
309
  * @property {string} [configPath] - Path to the configuration file.
284
310
  * @property {boolean} [ignoreBrowserslistConfig] - Ignores the browserslist configuration.
285
311
  * @property {boolean} [shippedProposals] - Enables support for shipped proposals.
312
+ * @property {boolean} [useAppendTransform] - Enables the append-to-appendChild transform plugin for compatibility with older browsers.
313
+ * @property {Array<string|Array|Function>} [plugins] - Additional Babel plugins to include in the transformation process.
286
314
  */
287
315
 
288
316
  /**
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Babel plugin to transform Element.append() calls to be compatible with older browsers.
3
+ * This plugin converts:
4
+ * - element.append("text") to element.appendChild(document.createTextNode("text"))
5
+ * - element.append(node) to element.appendChild(node)
6
+ * - element.append(node1, "text", node2) to a sequence of appendChild calls
7
+ *
8
+ * @param {Object} param0 - Babel plugin parameters
9
+ * @param {Object} param0.types - Babel types utility
10
+ * @returns {Object} Babel plugin object
11
+ */
12
+ export default function ({ types: t }) {
13
+ return {
14
+ name: 'append-polyfill-transform',
15
+ visitor: {
16
+ CallExpression(path) {
17
+ const callee = path.get('callee');
18
+
19
+ // Check for element.append(...) call pattern
20
+ if (!callee.isMemberExpression()) return;
21
+ if (!callee.get('property').isIdentifier({ name: 'append' })) return;
22
+
23
+ const args = path.node.arguments;
24
+ const objectNode = callee.get('object').node;
25
+
26
+ // Skip if no arguments
27
+ if (args.length === 0) return;
28
+
29
+ // Handle single argument case
30
+ if (args.length === 1) {
31
+ const arg = args[0];
32
+
33
+ // String literal case: element.append("text")
34
+ if (t.isStringLiteral(arg)) {
35
+ path.replaceWith(
36
+ t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
37
+ t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]),
38
+ ]),
39
+ );
40
+ } else {
41
+ // Node case: element.append(node)
42
+ callee.get('property').replaceWith(t.identifier('appendChild'));
43
+ }
44
+ return;
45
+ }
46
+
47
+ // Handle multiple arguments: element.append(node1, "text", node2)
48
+ const statements = args.map((arg) => {
49
+ // String literal case
50
+ if (t.isStringLiteral(arg)) {
51
+ return t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
52
+ t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]),
53
+ ]);
54
+ } else {
55
+ // Node case
56
+ return t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [arg]);
57
+ }
58
+ });
59
+
60
+ if (statements.length > 0) {
61
+ // Combine multiple statements into a sequence expression
62
+ path.replaceWith(t.sequenceExpression(statements));
63
+ }
64
+ },
65
+ },
66
+ };
67
+ }
package/minify.d.ts CHANGED
@@ -56,6 +56,17 @@ declare module 'uglify-js-minify-css-allfiles' {
56
56
  * Toggles enabling support for builtin/feature proposals that have shipped in browsers.
57
57
  */
58
58
  shippedProposals?: boolean;
59
+
60
+ /**
61
+ * Enables the append-to-appendChild transform plugin.
62
+ * When true, Element.append() calls are transformed to Element.appendChild() calls for compatibility with older browsers like Chrome 35.
63
+ */
64
+ useAppendTransform?: boolean;
65
+
66
+ /**
67
+ * Additional Babel plugins to include in the transformation process.
68
+ */
69
+ plugins?: Array<string | Array | Function>;
59
70
  }
60
71
 
61
72
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uglify-js-minify-css-allfiles",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "you will be able to minify all files as same file names which is js or css",
5
5
  "main": "minify.js",
6
6
  "type": "module",