File tree Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Original file line number Diff line number Diff line change 1
1
module . exports = ( eleventyConfig ) => {
2
- eleventyConfig . addTransform ( "jsmin" , require ( "./transforms/jsmin" ) ) ;
3
- eleventyConfig . addTransform ( "htmlmin" , require ( "./transforms/htmlmin" ) ) ;
2
+ eleventyConfig . addTransform ( "minify" , require ( "./transforms/minify" ) ) ;
4
3
5
4
return {
6
5
dir : {
Original file line number Diff line number Diff line change 1
- module . exports = async ( content , outputPath ) => {
2
- if ( ! outputPath . endsWith ( ".html" ) ) {
3
- return content ;
4
- }
1
+ const minify = require ( "html-minifier" ) . minify ;
2
+ const prettier = require ( "prettier" ) ;
5
3
6
- const $content = require ( "prettier" ) . format ( content , { parser : "html" } ) ;
4
+ module . exports = async ( content , outputPath ) => {
5
+ const $content = prettier . format ( content , { parser : "html" } ) ;
7
6
8
7
// If this is NOT a production build, return the prettified HTML for easier debugging.
9
8
if ( process . env . NODE_ENV !== "production" ) {
10
9
return $content ;
11
10
}
12
11
13
12
// Else, let's "aggressively" minify the HTML (and any inlined CSS/JavaScript).
14
- return require ( "html-minifier" ) . minify ( $content , {
13
+ return minify ( $content , {
15
14
collapseWhitespace : true ,
16
15
minifyCSS : true ,
17
16
minifyJS : true ,
Original file line number Diff line number Diff line change 1
- module . exports = async ( content , outputPath ) => {
2
- if ( ! outputPath . endsWith ( ".min.js" ) ) {
3
- return content ;
4
- }
1
+ const minify = require ( "terser" ) . minify ;
5
2
6
- const minified = await require ( "terser" ) . minify ( content , { } ) ;
3
+ module . exports = async ( content , outputPath ) => {
4
+ const minified = await minify ( content , { } ) ;
7
5
return minified . code ;
8
6
} ;
Original file line number Diff line number Diff line change
1
+ const extname = require ( "path" ) . extname ;
2
+
3
+ const htmlmin = require ( "./htmlmin" ) ;
4
+ const jsmin = require ( "./jsmin" ) ;
5
+
6
+ module . exports = async ( content , outputPath ) => {
7
+ const ext = extname ( outputPath ) ;
8
+ switch ( ext ) {
9
+ case ".html" :
10
+ return htmlmin ( content , outputPath ) ;
11
+ case ".js" :
12
+ return jsmin ( content , outputPath ) ;
13
+ default :
14
+ return content ;
15
+ }
16
+ } ;
You can’t perform that action at this time.
0 commit comments