uglify-js-minify-css-allfiles 2.2.4 → 2.3.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.3.1] - 2025-02-13
9
+
10
+ ### Fixed
11
+
12
+ - Fixed `ext is not defined` error in image versioning log messages
13
+
14
+ ## [2.3.0] - 2025-02-13
15
+
16
+ ### Added
17
+
18
+ - Image versioning system with content-based hashing for cache busting
19
+ - Support for multiple image formats (PNG, JPEG, GIF, SVG, WebP, etc.)
20
+ - Automatic hash generation for images in CSS files
21
+ - Random hash generation for JS image references
22
+ - Support for various image path formats including absolute, relative, data URIs
23
+ - Complex CSS background and image-set() syntax support
24
+ - New `useVersioning` option with configurable file extensions
25
+ - Hash management system for tracking and updating image versions
26
+ - Comprehensive image path resolution and processing utilities
27
+
28
+ ### Changed
29
+
30
+ - Enhanced documentation with detailed image versioning examples and configuration options
31
+ - Improved path resolution system to handle various image reference formats
32
+ - Updated logging system to track image versioning operations
33
+
8
34
  ## [2.2.4] - 2024-08-23
9
35
 
10
36
  ### Changed
package/README.md CHANGED
@@ -1,36 +1,39 @@
1
- [![NPM downloads][npm-downloads]][npm-url]
2
- [![NPM total downloads][npm-total-downloads]][npm-url]
3
-
4
- | &nbsp;<br>[![Donate][donate-badge]][donate-url] <br>&nbsp; | Your help is appreciated! [Create a PR][create-pr] or just [buy me a coffee][donate-url] |
5
- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
6
-
7
- [npm-url]: https://www.npmjs.com/package/uglify-js-minify-css-allfiles
8
- [npm-downloads]: https://img.shields.io/npm/dm/uglify-js-minify-css-allfiles.svg
9
- [npm-total-downloads]: https://img.shields.io/npm/dt/uglify-js-minify-css-allfiles.svg?label=total+downloads
10
- [donate-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-Donate-red.svg
11
- [donate-url]: https://github.com/sponsors/oinochoe
12
- [create-pr]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/pulls
13
-
14
1
  # uglify-js-minify-css-allfiles
15
2
 
16
3
  A powerful tool to minify and obfuscate JavaScript and CSS files in your project.
17
4
  It helps protect your code in deployment environments and makes it less recognizable to others, all through a simple CLI interface.
18
5
  You can easily minify all files in a specific folder, with the option to exclude certain directories.
19
6
 
7
+ [![NPM downloads][npm-downloads]][npm-url]
8
+ [![NPM total downloads][npm-total-downloads]][npm-url]
20
9
  [![NPM](https://nodei.co/npm/uglify-js-minify-css-allfiles.png?downloads=true&stars=true)](https://www.npmjs.com/package/uglify-js-minify-css-allfiles)
21
10
 
22
- ---
23
-
24
11
  ## Table of Contents
25
12
 
26
13
  - [Installation](#installation)
14
+ - [Features](#features)
27
15
  - [Usage](#usage)
28
16
  - [Parameters](#parameters)
29
17
  - [Options](#options)
18
+ - [Advanced Features](#advanced-features)
19
+ - [Babel Integration](#babel-integration)
20
+ - [Image Versioning](#image-versioning)
21
+ - [Logging System](#logging-system)
22
+ - [API Reference](#api-reference)
30
23
  - [Minification Options](#minification-options)
31
- - [Changelog](#changelog)
24
+ - [Contributing](#contributing)
32
25
  - [License](#license)
33
26
 
27
+ ## Features
28
+
29
+ - 🚀 JavaScript and CSS minification with advanced options
30
+ - 📦 Babel transformation support for modern JavaScript
31
+ - 🖼️ Automatic image versioning and cache busting
32
+ - 📝 Comprehensive logging system
33
+ - 🛡️ Configurable file exclusion
34
+ - 🔄 ES module support
35
+ - 📊 Processing statistics and summaries
36
+
34
37
  ## Installation
35
38
 
36
39
  Install with `npm`:
@@ -41,136 +44,220 @@ $ npm i uglify-js-minify-css-allfiles
41
44
 
42
45
  ## Usage
43
46
 
44
- 1. Basic usage (no Babel):
45
-
46
- ```js
47
- import minifyAll from 'uglify-js-minify-css-allfiles';
48
-
49
- await minifyAll('./src/');
50
- ```
51
-
52
- 2. Using options:
53
-
54
- ```js
55
- import minifyAll from 'uglify-js-minify-css-allfiles';
56
-
57
- await minifyAll('./src/', {
58
- excludeFolder: 'node_modules',
59
- useBabel: {
60
- targets: 'chrome 40',
61
- modules: false,
62
- useBuiltIns: 'usage',
63
- corejs: 3,
64
- },
65
- useLog: {
66
- logDir: 'logs',
67
- retentionDays: 30,
68
- logLevel: 'info',
69
- dateFormat: 'YYYY-MM-DD',
70
- timeZone: 'UTC',
71
- logToConsole: true,
72
- logToFile: true,
73
- },
74
- jsMinifyOptions: {
75
- compress: {
76
- dead_code: true,
77
- drop_debugger: true,
78
- conditionals: true,
79
- evaluate: true,
80
- booleans: true,
81
- loops: true,
82
- unused: true,
83
- hoist_funs: true,
84
- keep_fargs: false,
85
- hoist_vars: true,
86
- if_return: true,
87
- join_vars: true,
88
- cascade: true,
89
- side_effects: true,
90
- warnings: false,
91
- },
92
- },
93
- cssMinifyOptions: {
94
- level: 2,
95
- },
96
- });
97
- ```
98
-
99
- ## Parameters
100
-
101
- The `minifyAll` function accepts the following parameters:
102
-
103
- | Parameter | Type | Default | Description |
104
- | ------------- | ------ | ------- | -------------------------------------------------------------------------------------------- |
105
- | `contentPath` | string | - | The path to the directory containing the files to be minified. This is a required parameter. |
106
- | `options` | object | `{}` | An object containing options for minification, Babel, and logging. |
107
-
108
- ## Options
109
-
110
- The `options` object can have the following properties:
111
-
112
- | Property | Type | Default | Description |
113
- | ------------------ | ----------------- | ------- | ------------------------------------------------------------------------------------------ |
114
- | `excludeFolder` | string | `''` | The name of a folder to exclude from minification. |
115
- | `useBabel` | boolean \| object | `false` | If `true`, enables Babel with default settings. If an object, specifies Babel options. |
116
- | `useLog` | boolean \| object | `true` | If `true`, enables logging with default settings. If an object, specifies logging options. |
117
- | `jsMinifyOptions` | object | `{}` | Options for JavaScript minification (passed to UglifyJS). |
118
- | `cssMinifyOptions` | object | `{}` | Options for CSS minification (passed to CleanCSS). |
47
+ ### Basic Usage
119
48
 
120
- ### Babel Options
49
+ ```js
50
+ import minifyAll from 'uglify-js-minify-css-allfiles';
121
51
 
122
- When `useBabel` is an object, it can have the following properties:
52
+ await minifyAll('./src/');
53
+ ```
123
54
 
124
- | Property | Type | Description |
125
- | ------------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------- |
126
- | `targets` | string \| object | Specifies the target environments. |
127
- | `modules` | string \| false | Enables transformation of ES6 module syntax to another module type. |
128
- | `useBuiltIns` | 'usage' \| 'entry' \| false | Configures how babel-preset-env handles polyfills. |
129
- | `corejs` | number \| object | Specifies the core-js version. |
130
- | ... (other @babel/preset-env options) | Various | Refer to [@babel/preset-env documentation](https://babeljs.io/docs/en/babel-preset-env) for more options. |
55
+ ### Advanced Usage
56
+
57
+ ```js
58
+ import minifyAll from 'uglify-js-minify-css-allfiles';
59
+
60
+ await minifyAll('./src/', {
61
+ excludeFolder: 'node_modules',
62
+ useBabel: {
63
+ targets: 'chrome 40',
64
+ modules: false,
65
+ useBuiltIns: 'usage',
66
+ corejs: 3,
67
+ },
68
+ useLog: {
69
+ logDir: 'logs',
70
+ retentionDays: 30,
71
+ logLevel: 'info',
72
+ dateFormat: 'YYYY-MM-DD',
73
+ timeZone: 'UTC',
74
+ logToConsole: true,
75
+ logToFile: true,
76
+ },
77
+ jsMinifyOptions: {
78
+ compress: {
79
+ dead_code: true,
80
+ drop_debugger: true,
81
+ pure_funcs: ['console.log'],
82
+ conditionals: true,
83
+ evaluate: true,
84
+ unused: true,
85
+ },
86
+ mangle: true,
87
+ },
88
+ cssMinifyOptions: {
89
+ level: 2,
90
+ },
91
+ useVersioning: {
92
+ extensions: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'],
93
+ },
94
+ });
95
+ ```
131
96
 
132
- ### Log Options
97
+ ## Advanced Features
133
98
 
134
- When `useLog` is an object, it can have the following properties:
99
+ ### Babel Integration
135
100
 
136
- | Property | Type | Default | Description |
137
- | --------------- | ------- | -------------- | --------------------------------------------------------------------- |
138
- | `logDir` | string | `'logs'` | Specifies the directory for log files. |
139
- | `retentionDays` | number | 30 | Number of days to retain log files. |
140
- | `logLevel` | string | `'info'` | Specifies the level of logging (e.g., `'info'`, `'warn'`, `'error'`). |
141
- | `dateFormat` | string | `'YYYY-MM-DD'` | Format for the date in log entries. |
142
- | `timeZone` | string | `'UTC'` | Time zone for timestamps in log entries. |
143
- | `logToConsole` | boolean | `true` | Determines if logs should also be output to the console. |
144
- | `logToFile` | boolean | `true` | Determines if logs should be written to a file. |
101
+ Built-in Babel support for modern JavaScript transpilation:
145
102
 
146
- ## Minification Options
103
+ - Configurable target environments
104
+ - Module transformation options
105
+ - Built-ins and CoreJS integration
106
+ - Customizable plugin/preset options
147
107
 
148
- ### JavaScript Minification Options
108
+ ```js
109
+ await minifyAll('./src/', {
110
+ useBabel: {
111
+ targets: 'chrome 40',
112
+ modules: false,
113
+ useBuiltIns: 'usage',
114
+ corejs: 3,
115
+ },
116
+ });
117
+ ```
149
118
 
150
- The `jsMinifyOptions` object is passed directly to UglifyJS. For a full list of available options, please refer to the [UglifyJS documentation](https://github.com/mishoo/UglifyJS#minify-options).
119
+ ### Image Versioning
120
+
121
+ Automatic versioning for image references in JS and CSS files:
122
+
123
+ - Content-based hashing for images in CSS files
124
+ - Random hash generation for JS image references
125
+ - Support for multiple image formats (PNG, JPEG, GIF, SVG, WebP, etc.)
126
+ - Handles various image path formats:
127
+ - Absolute and relative paths
128
+ - Data URIs
129
+ - HTTP/HTTPS URLs
130
+ - Complex CSS background declarations
131
+ - image-set() syntax support
132
+
133
+ ```js
134
+ await minifyAll('./src/', {
135
+ useVersioning: {
136
+ extensions: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'],
137
+ },
138
+ });
139
+ ```
151
140
 
152
- Some commonly used options include:
141
+ ### Logging System
142
+
143
+ Comprehensive logging capabilities:
144
+
145
+ - Multiple log levels (error, warn, info, debug)
146
+ - File rotation with retention policies
147
+ - Customizable date formats and timezones
148
+ - Console and file output options
149
+ - Processing statistics and summaries
150
+
151
+ ```js
152
+ await minifyAll('./src/', {
153
+ useLog: {
154
+ logDir: 'logs',
155
+ retentionDays: 30,
156
+ logLevel: 'info',
157
+ dateFormat: 'YYYY-MM-DD',
158
+ timeZone: 'UTC',
159
+ logToConsole: true,
160
+ logToFile: true,
161
+ },
162
+ });
163
+ ```
153
164
 
154
- - `compress`: An object specifying compression options.
155
- - `mangle`: Controls name mangling. Can be a boolean or an object with more specific options.
156
- - `output`: An object controlling the output format.
165
+ ## API Reference
157
166
 
158
- ### CSS Minification Options
167
+ ### minifyAll(contentPath, options)
168
+
169
+ Main function to process files.
170
+
171
+ - `contentPath` (string): Source directory path
172
+ - `options` (object): Configuration options
173
+ - `excludeFolder` (string): Directory to exclude
174
+ - `useBabel` (boolean|object): Babel configuration
175
+ - `useLog` (boolean|object): Logging configuration
176
+ - `jsMinifyOptions` (object): JavaScript minification options
177
+ - `cssMinifyOptions` (object): CSS minification options
178
+ - `useVersioning` (object): Image versioning configuration
179
+ - `extensions` (string[]): List of image extensions to version
159
180
 
160
- The `cssMinifyOptions` object is passed directly to Clean-CSS. For a full list of available options, please refer to the [Clean-CSS documentation](https://github.com/clean-css/clean-css#constructor-options).
181
+ ### Babel Options
182
+
183
+ The `useBabel` object supports all @babel/preset-env options:
184
+
185
+ ```js
186
+ {
187
+ targets: string | string[] | Object,
188
+ modules: 'amd' | 'umd' | 'systemjs' | 'commonjs' | false,
189
+ debug: boolean,
190
+ include: string[],
191
+ exclude: string[],
192
+ useBuiltIns: 'usage' | 'entry' | false,
193
+ corejs: 2 | 3 | { version: 2 | 3, proposals: boolean },
194
+ forceAllTransforms: boolean,
195
+ configPath: string,
196
+ ignoreBrowserslistConfig: boolean,
197
+ shippedProposals: boolean
198
+ }
199
+ ```
200
+
201
+ ### JavaScript Minification Options
161
202
 
162
- Some commonly used options include:
203
+ Supports all UglifyJS options:
204
+
205
+ ```js
206
+ {
207
+ compress: {
208
+ dead_code: boolean,
209
+ drop_debugger: boolean,
210
+ pure_funcs: string[],
211
+ conditionals: boolean,
212
+ evaluate: boolean,
213
+ booleans: boolean,
214
+ loops: boolean,
215
+ unused: boolean,
216
+ if_return: boolean,
217
+ join_vars: boolean,
218
+ cascade: boolean,
219
+ side_effects: boolean
220
+ },
221
+ mangle: boolean | Object,
222
+ output: {
223
+ beautify: boolean,
224
+ comments: boolean | 'all' | 'some' | RegExp
225
+ }
226
+ }
227
+ ```
163
228
 
164
- - `level`: Optimization level (0, 1, or 2).
165
- - `compatibility`: Browser compatibility (e.g., 'ie7', '\*').
166
- - `format`: Output formatting options.
229
+ ### CSS Minification Options
167
230
 
168
- ## Changelog
231
+ Supports Clean-CSS options:
232
+
233
+ ```js
234
+ {
235
+ level: 0 | 1 | 2 | {
236
+ 1: {
237
+ all: boolean,
238
+ specialComments: boolean | string
239
+ },
240
+ 2: {
241
+ mergeSemantically: boolean,
242
+ restructureRules: boolean
243
+ }
244
+ },
245
+ compatibility: string | string[],
246
+ format: string | Object
247
+ }
248
+ ```
169
249
 
170
- See CHANGELOG.md for details on each release.
250
+ ## Contributing
171
251
 
172
- [Changelog](/CHANGELOG.md)
252
+ Your help is appreciated! [Create a PR][create-pr] or just [buy me a coffee][donate-url]
173
253
 
174
254
  ## License
175
255
 
176
256
  MIT. See [LICENSE.md](https://github.com/oinochoe/uglify-js-minify-css-allfiles/blob/master/LICENSE) for details.
257
+
258
+ [npm-url]: https://www.npmjs.com/package/uglify-js-minify-css-allfiles
259
+ [npm-downloads]: https://img.shields.io/npm/dm/uglify-js-minify-css-allfiles.svg
260
+ [npm-total-downloads]: https://img.shields.io/npm/dt/uglify-js-minify-css-allfiles.svg?label=total+downloads
261
+ [donate-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-Donate-red.svg
262
+ [donate-url]: https://github.com/sponsors/oinochoe
263
+ [create-pr]: https://github.com/oinochoe/uglify-js-minify-css-allfiles/pulls
package/demo.js CHANGED
@@ -5,4 +5,7 @@ minifyAll('./test/', {
5
5
  useBabel: {
6
6
  targets: 'chrome 40',
7
7
  },
8
+ useVersioning: {
9
+ extensions: ['.png', '.jpg', '.webp', '.avif', '.svg'],
10
+ },
8
11
  });