uglify-js-minify-css-allfiles 2.5.0 → 2.6.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
@@ -108,6 +108,7 @@ await minifyAll('./src/', {
108
108
  extensions: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'],
109
109
  },
110
110
  useJsMap: true,
111
+ useCssMap: true
111
112
  });
112
113
  ```
113
114
 
@@ -233,19 +234,19 @@ await minifyAll('./src/', {
233
234
 
234
235
  ### Source Maps
235
236
 
236
- Generate source maps for JavaScript files to aid in debugging minified code:
237
+ Generate source maps for both JavaScript and CSS files to aid in debugging minified code:
237
238
 
238
239
  - Maps compressed code back to original source code
239
- - Automatically creates `.map` files alongside minified JavaScript
240
+ - Automatically creates `.map` files alongside minified files
240
241
  - Seamless integration with browser developer tools
241
- - Works with or without Babel transformation
242
+ - Works with or without Babel/PostCSS transformation
242
243
  - Helps maintain debuggability in production environments
243
244
 
244
245
  ```js
245
246
  await minifyAll('./src/', {
246
247
  useJsMap: true,
248
+ useCssMap: true
247
249
  });
248
- ```
249
250
 
250
251
  ## API Reference
251
252
 
@@ -264,6 +265,7 @@ Main function to process files.
264
265
  - `useVersioning` (object): Image versioning configuration
265
266
  - `extensions` (string[]): List of image extensions to version
266
267
  - `useJsMap` (boolean): Enable source map generation for JavaScript files
268
+ - `useCssMap` (boolean): Enable source map generation for CSS files
267
269
 
268
270
  ### Babel Options
269
271
 
package/demo.js CHANGED
@@ -21,4 +21,5 @@ minifyAll('./test/', {
21
21
  extensions: ['.png', '.jpg', '.webp', '.avif', '.svg'],
22
22
  },
23
23
  useJsMap: true,
24
+ useCssMap: true,
24
25
  });
package/dist/module.js CHANGED
@@ -179,6 +179,7 @@ async function resolveBabelOptions(useBabel) {
179
179
  * @param {Object} [options.cssMinifyOptions] - CSS minification options.
180
180
  * @param {Object} [options.postcssOptions] - PostCSS processing options.
181
181
  * @param {boolean} [options.useJsMap] - JavaScript map file options.
182
+ * @param {boolean} [options.useCssMap] - Css map file options.
182
183
  * @returns {Promise<void>}
183
184
  */
184
185
  async function processFile(filePath, logger, options) {
@@ -233,16 +234,32 @@ async function processFile(filePath, logger, options) {
233
234
  await writeFile(filePath, result.code, logger);
234
235
  }
235
236
  } else if (fileExtension === '.css') {
236
- // PostCSS 옵션 설정
237
237
  const postcssOptions = options.postcssOptions || null;
238
-
239
- // CSS 처리 (PostCSS + CleanCSS)
240
- const output = await minifyCSS(fileContent, options.cssMinifyOptions, postcssOptions, filePath);
238
+ const output = await minifyCSS(fileContent, options.cssMinifyOptions, postcssOptions, filePath, options.useCssMap);
241
239
 
242
240
  if (output.warnings.length > 0) {
243
241
  await logger?.warn('CSS minification warnings', { filePath, warnings: output.warnings });
244
242
  }
245
- await writeFile(filePath, output.styles, logger);
243
+
244
+ if (options.useCssMap && output.sourceMap) {
245
+ const fileName = path.basename(filePath);
246
+ const mapFilePath = filePath.replace('.css', '.css.map');
247
+
248
+ // Add source map reference to the CSS file
249
+ const sourceMapComment = `\n/*# sourceMappingURL=${fileName}.map */`;
250
+ await writeFile(filePath, output.styles + sourceMapComment, logger);
251
+
252
+ // Write the source map file
253
+ try {
254
+ const sourceMap = JSON.stringify(output.sourceMap);
255
+ await writeFile(mapFilePath, sourceMap, logger);
256
+ await logger?.info('Generated CSS source map', { filePath: mapFilePath });
257
+ } catch (error) {
258
+ await logger?.error('Failed to write CSS source map', { filePath: mapFilePath, error: error.message });
259
+ }
260
+ } else {
261
+ await writeFile(filePath, output.styles, logger);
262
+ }
246
263
  } else {
247
264
  // `Unsupported file type, skipping: ${filePath}`;
248
265
  return;
@@ -317,6 +334,7 @@ async function processFile(filePath, logger, options) {
317
334
  * @property {PostCSSOptions|boolean} [usePostCSS=false] - PostCSS configuration options.
318
335
  * @property {string[]|null} [useVersioning=null] - Options for file versioning.
319
336
  * @property {boolean} [useJsMap=false] - Whether to use JavaScript Map file.
337
+ * @property {boolean} [useCssMap=false] - Whether to use CSS Map file.
320
338
  */
321
339
 
322
340
  /**
@@ -337,6 +355,7 @@ export default async function minifyAll(contentPath, options = {}) {
337
355
  usePostCSS = false,
338
356
  useVersioning = null,
339
357
  useJsMap = false,
358
+ useCssMap = false,
340
359
  } = options;
341
360
 
342
361
  let logger = null;
@@ -351,6 +370,7 @@ export default async function minifyAll(contentPath, options = {}) {
351
370
  usePostCSS: !!usePostCSS,
352
371
  useVersioning: !!useVersioning,
353
372
  useJsMap,
373
+ useCssMap,
354
374
  });
355
375
  }
356
376
 
@@ -369,6 +389,7 @@ export default async function minifyAll(contentPath, options = {}) {
369
389
  cssMinifyOptions,
370
390
  postcssOptions: usePostCSS === true ? {} : usePostCSS,
371
391
  useJsMap,
392
+ useCssMap,
372
393
  };
373
394
 
374
395
  try {
@@ -43,15 +43,19 @@ export function minifyJS(content, options = {}) {
43
43
  * @param {Object} [options={}] - Clean-CSS options.
44
44
  * @param {Object} [postcssOptions=null] - PostCSS configuration options, if null PostCSS is skipped.
45
45
  * @param {string} [filePath=''] - Path to the file being processed.
46
- * @returns {Promise<{styles: string, warnings: string[]}>} Minified CSS and warnings.
46
+ * @param {boolean} [useCssMap=false] - Whether to generate and use a CSS source map file.
47
+ * @returns {Promise<{styles: string, warnings: string[], map: string}>} Minified CSS, warnings and source map.
47
48
  */
48
- export async function minifyCSS(content, options = {}, postcssOptions = null, filePath = '') {
49
+ export async function minifyCSS(content, options = {}, postcssOptions = null, filePath = '', useCssMap = false) {
49
50
  const defaultOptions = {
50
51
  level: { 1: { all: false } },
52
+ sourceMap: !!useCssMap,
53
+ sourceMapInlineSources: !!useCssMap,
51
54
  };
52
55
 
53
56
  const mergedOptions = { ...defaultOptions, ...options };
54
57
  let processedCSS = content;
58
+ let previousSourceMap = null;
55
59
 
56
60
  // Check if PostCSS is available and enabled
57
61
  if (postCSSAvailable === null) {
@@ -64,6 +68,10 @@ export async function minifyCSS(content, options = {}, postcssOptions = null, fi
64
68
  const result = await processWithPostCSS(content, filePath, postcssOptions);
65
69
  processedCSS = result.css;
66
70
 
71
+ if (result.map) {
72
+ previousSourceMap = result.map.toString();
73
+ }
74
+
67
75
  // Handle warnings
68
76
  if (result.messages && result.messages.length > 0) {
69
77
  console.warn(`PostCSS warnings for ${filePath}:`, result.messages.map((msg) => msg.text).join('\n'));
@@ -76,6 +84,6 @@ export async function minifyCSS(content, options = {}, postcssOptions = null, fi
76
84
 
77
85
  // Use CleanCSS for final minification
78
86
  return new Promise((resolve) => {
79
- new CleanCSS(mergedOptions).minify(processedCSS, (error, output) => resolve(output));
87
+ new CleanCSS(mergedOptions).minify(processedCSS, previousSourceMap, (error, output) => resolve(output));
80
88
  });
81
89
  }
@@ -52,11 +52,13 @@ export async function processWithPostCSS(content, filePath = '', options = {}) {
52
52
  const result = await postcss(plugins).process(content, {
53
53
  from: filePath || undefined,
54
54
  to: filePath || undefined,
55
+ map: { inline: true },
55
56
  });
56
57
 
57
58
  return {
58
59
  css: result.css,
59
60
  messages: result.messages,
61
+ map: result.map,
60
62
  };
61
63
  } catch (error) {
62
64
  console.error('Error processing CSS with PostCSS:', error);
package/minify.d.ts CHANGED
@@ -187,6 +187,13 @@ declare module 'uglify-js-minify-css-allfiles' {
187
187
  * @default false
188
188
  */
189
189
  useJsMap?: boolean;
190
+
191
+ /**
192
+ * Enables source map generation for CSS files during minification.
193
+ * Source maps help with debugging by mapping minified CSS back to original source code.
194
+ * @default false
195
+ */
196
+ useCssMap?: boolean;
190
197
  }
191
198
 
192
199
  /**
@@ -215,6 +222,7 @@ declare module 'uglify-js-minify-css-allfiles' {
215
222
  * retentionDays: 7
216
223
  * },
217
224
  * useJsMap: true // Enable source map generation
225
+ * useCssMap: true // Enable source map generation
218
226
  * });
219
227
  * ```
220
228
  */
package/package.json CHANGED
@@ -1,56 +1,56 @@
1
1
  {
2
- "name": "uglify-js-minify-css-allfiles",
3
- "version": "2.5.0",
4
- "description": "you will be able to minify all files as same file names which is js or css",
5
- "main": "minify.js",
6
- "type": "module",
7
- "types": "minify.d.ts",
8
- "exports": {
9
- ".": "./minify.js"
10
- },
11
- "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/oinochoe/uglify-js-minify-css-allfiles.git"
17
- },
18
- "publishConfig": {
19
- "registry": "https://registry.npmjs.org/"
20
- },
21
- "keywords": [
22
- "ugly-code",
23
- "uglyCode",
24
- "uglify-js",
25
- "minify-es6",
26
- "uglifyjs-es6",
27
- "minifycss",
28
- "miniCss",
29
- "cleanCss",
30
- "minifyCss",
31
- "comporessor",
32
- "allfile minify",
33
- "allfiles minify",
34
- "all files uglify"
35
- ],
36
- "author": {
37
- "name": "yeongmin kim",
38
- "email": "copstyle86@gmail.com",
39
- "url": "https://oinochoe.github.io/portfolio/"
40
- },
41
- "license": "MIT",
42
- "bugs": {
43
- "url": "https://github.com/oinochoe/uglify-js-minify-css-allfiles/issues",
44
- "email": "copstyle86@gmail.com"
45
- },
46
- "homepage": "https://github.com/oinochoe/uglify-js-minify-css-allfiles#readme",
47
- "devDependencies": {
48
- "@babel/core": "^7.25.2",
49
- "@babel/preset-env": "^7.25.3",
50
- "clean-css": "^4.2.4",
51
- "postcss": "^8.5.3",
52
- "postcss-preset-env": "^10.1.5",
53
- "uglify-js": "^3.19.2",
54
- "uglify-js-es6": "^2.8.9"
55
- }
2
+ "name": "uglify-js-minify-css-allfiles",
3
+ "version": "2.6.0",
4
+ "description": "you will be able to minify all files as same file names which is js or css",
5
+ "main": "minify.js",
6
+ "type": "module",
7
+ "types": "minify.d.ts",
8
+ "exports": {
9
+ ".": "./minify.js"
10
+ },
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/oinochoe/uglify-js-minify-css-allfiles.git"
17
+ },
18
+ "publishConfig": {
19
+ "registry": "https://registry.npmjs.org/"
20
+ },
21
+ "keywords": [
22
+ "ugly-code",
23
+ "uglyCode",
24
+ "uglify-js",
25
+ "minify-es6",
26
+ "uglifyjs-es6",
27
+ "minifycss",
28
+ "miniCss",
29
+ "cleanCss",
30
+ "minifyCss",
31
+ "comporessor",
32
+ "allfile minify",
33
+ "allfiles minify",
34
+ "all files uglify"
35
+ ],
36
+ "author": {
37
+ "name": "yeongmin kim",
38
+ "email": "copstyle86@gmail.com",
39
+ "url": "https://oinochoe.github.io/portfolio/"
40
+ },
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/oinochoe/uglify-js-minify-css-allfiles/issues",
44
+ "email": "copstyle86@gmail.com"
45
+ },
46
+ "homepage": "https://github.com/oinochoe/uglify-js-minify-css-allfiles#readme",
47
+ "dependencies": {
48
+ "@babel/core": "^7.25.2",
49
+ "@babel/preset-env": "^7.25.3",
50
+ "clean-css": "^4.2.4",
51
+ "postcss": "^8.5.3",
52
+ "postcss-preset-env": "^10.1.5",
53
+ "uglify-js": "^3.19.2",
54
+ "uglify-js-es6": "^2.8.9"
55
+ }
56
56
  }