@@ -111,6 +111,7 @@ export default class I18nextPlugin {
111
111
protected startTime = Date . now ( ) ;
112
112
protected prevTimestamps : { [ file : string ] : number } = { } ;
113
113
protected sourceMaps : { [ key : string ] : SourceMapConsumer } = { } ;
114
+ protected missingDirInitialized = false ;
114
115
115
116
public constructor ( option : Option ) {
116
117
this . option = _ . defaults ( option , {
@@ -147,6 +148,7 @@ export default class I18nextPlugin {
147
148
}
148
149
} ) ;
149
150
this . context = compiler . options . context || "" ;
151
+ this . initMissingDir ( ) ;
150
152
151
153
compiler . plugin ( "compilation" , ( compilation , data ) => {
152
154
// reset for new compliation
@@ -185,6 +187,21 @@ export default class I18nextPlugin {
185
187
compiler . plugin ( "after-emit" , this . onAfterEmit . bind ( this ) ) ;
186
188
}
187
189
190
+ protected async initMissingDir ( ) {
191
+ if ( this . missingDirInitialized ) {
192
+ return ;
193
+ }
194
+
195
+ const template = path . resolve ( this . context , this . option . pathToSaveMissing ) ;
196
+ await Promise . all ( this . option . namespaces . map ( ns => this . option . languages . map ( async lng => {
197
+ const dirPath = path . dirname ( getPath ( template , lng , ns ) ) ;
198
+ if ( ! await exists ( dirPath ) ) {
199
+ await mkdir ( dirPath ) ;
200
+ }
201
+ } ) ) ) ;
202
+ this . missingDirInitialized = true ;
203
+ }
204
+
188
205
protected async onEmit ( compilation : wp . Compilation , callback : ( err ?: Error ) => void ) {
189
206
// emit translation files
190
207
this . prevTimestamps = compilation . fileTimestamps ;
@@ -234,6 +251,7 @@ export default class I18nextPlugin {
234
251
) ) ;
235
252
try {
236
253
// write missing
254
+ await this . initMissingDir ( ) ;
237
255
await Promise . all ( _ . map ( this . missingKeys , async ( namespaces , lng ) => {
238
256
const resourceTemplate = path . join ( this . context , getPath ( this . option . pathToSaveMissing , lng ) ) ;
239
257
const resourceDir = path . dirname ( resourceTemplate ) ;
0 commit comments