@@ -89,6 +89,50 @@ function getSpecifiedJSONFiles(sourceDir, specifiedDirArray) {
89
89
return filesArray
90
90
}
91
91
92
+ function getWidgetI18nJSONFiles ( sourceDir ) {
93
+ let widgetsOption = { }
94
+ try {
95
+ const manifestFile = path . join ( sourceDir , 'manifest.json' )
96
+ const manifest = readJson ( manifestFile )
97
+ widgetsOption = manifest ?. router . widgets || { }
98
+ } catch ( err ) {
99
+ console . error ( err )
100
+ }
101
+ let filesArray = [ ]
102
+ for ( let key in widgetsOption ) {
103
+ const widgetPath = widgetsOption [ key ] . path
104
+ const dir = path . join ( sourceDir , widgetPath , 'i18n' )
105
+ // const jsonPath = onlyRoot ? '*.json' : '**/**.json'
106
+ if ( fs . existsSync ( dir ) ) {
107
+ filesArray = filesArray . concat ( getFiles ( '*.json' , dir ) )
108
+ }
109
+ }
110
+ return filesArray
111
+ }
112
+
113
+ function minifyWidgetI18nJSONFiles ( targetDir ) {
114
+ let widgetsOption = { }
115
+ try {
116
+ const manifestFile = path . join ( targetDir , 'manifest.json' )
117
+ const manifest = readJson ( manifestFile )
118
+ widgetsOption = manifest ?. router . widgets || { }
119
+ } catch ( err ) {
120
+ console . error ( err )
121
+ }
122
+ let arr = [ ]
123
+ for ( let key in widgetsOption ) {
124
+ const widgetPath = widgetsOption [ key ] . path
125
+ const dir = path . join ( targetDir , widgetPath , 'i18n' )
126
+ if ( fs . existsSync ( dir ) ) {
127
+ const jsonFiles = getFiles ( '*.json' , dir )
128
+ jsonFiles . forEach ( ( filePath ) => {
129
+ arr . push ( filePath )
130
+ minifyJson ( filePath , filePath )
131
+ } )
132
+ }
133
+ }
134
+ }
135
+
92
136
function minifyJson ( source , target ) {
93
137
try {
94
138
const contentStr = fs . readFileSync ( source , 'utf8' )
@@ -181,6 +225,7 @@ ResourcePlugin.prototype.apply = function (compiler) {
181
225
let files = getFiles ( `**/+(!(${ EXT_PATTERN } )|manifest.json|sitemap.json)` , sourceDir )
182
226
files = files . concat (
183
227
getSpecifiedJSONFiles ( sourceDir , JSON_DIRECTORY_NEED_PACKAGING ) ,
228
+ getWidgetI18nJSONFiles ( sourceDir ) ,
184
229
getSkeletonConfigFile ( sourceDir )
185
230
)
186
231
let iconPath
@@ -307,6 +352,8 @@ ResourcePlugin.prototype.apply = function (compiler) {
307
352
308
353
minifySpecifiedJSONFiles ( targetDir , JSON_DIRECTORY_NEED_PACKAGING )
309
354
355
+ minifyWidgetI18nJSONFiles ( targetDir )
356
+
310
357
minifySitemap ( targetDir )
311
358
312
359
minifySkeletonConfig ( targetDir )
0 commit comments