File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 15
15
"name" : " pawcode Development"
16
16
},
17
17
"scripts" : {
18
- "postversion" : " pnpm run build:ngsw && pnpm run build:sitemap" ,
19
18
"build" : " ng build" ,
19
+ "postbuild" : " node ./scripts/minify-i18n.js" ,
20
20
"build:ngsw" : " node ./scripts/update-ngsw.js" ,
21
21
"build:sitemap" : " node ./scripts/update-sitemap.js" ,
22
+ "chromatic" : " chromatic --build-script-name storybook:build --exit-zero-on-changes" ,
22
23
"preinstall" : " npx only-allow pnpm" ,
23
24
"lint" : " ng lint" ,
24
25
"ng" : " ng" ,
28
29
"start" : " ng serve" ,
29
30
"storybook" : " ng run rainbow-palette:storybook" ,
30
31
"storybook:build" : " ng run rainbow-palette:build-storybook" ,
31
- "chromatic" : " chromatic --build-script-name storybook:build --exit-zero-on-changes" ,
32
32
"test" : " ng test" ,
33
33
"test:ci" : " ng test --no-watch --no-progress --browsers=ChromeHeadless" ,
34
+ "postversion" : " pnpm run build:ngsw && pnpm run build:sitemap" ,
34
35
"watch" : " ng build --watch --configuration development"
35
36
},
36
37
"dependencies" : {
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ // List of supported languages
5
+ const languages = [ 'en' , 'de' ] ;
6
+
7
+ /**
8
+ * Minify a translation file
9
+ */
10
+ function minifyTranslation ( language ) {
11
+ // Read the file size before minification
12
+ const file = `../dist/rainbow-palette/browser/assets/i18n/${ language } .json` ;
13
+ const before = fs . statSync ( path . resolve ( __dirname , file ) ) . size ;
14
+
15
+ // Minify the file
16
+ const content = fs . readFileSync ( path . resolve ( __dirname , file ) , 'utf8' ) ;
17
+ const minified = JSON . stringify ( JSON . parse ( content ) ) ;
18
+ fs . writeFileSync ( path . resolve ( __dirname , file ) , minified ) ;
19
+
20
+ // Read the file size after minification
21
+ const after = fs . statSync ( path . resolve ( __dirname , file ) ) . size ;
22
+
23
+ // Log the results
24
+ const beforeKB = ( before / 1024 ) . toFixed ( 2 ) ;
25
+ const afterKB = ( after / 1024 ) . toFixed ( 2 ) ;
26
+ const saved = ( 100 - ( after / before ) * 100 ) . toFixed ( 2 ) ;
27
+ console . log ( `Minified "${ language } .json": ${ beforeKB } kB -> ${ afterKB } kB (-${ saved } %)` ) ;
28
+ }
29
+
30
+ // Minify all translation files
31
+ languages . forEach ( minifyTranslation ) ;
You can’t perform that action at this time.
0 commit comments