1- const path = require ( 'path' )
2- const fs = require ( 'fs' )
1+ import * as path from 'path'
2+ import * as fs from 'fs'
3+ import webpack from 'webpack'
34
45// Genearate the messages used by Chrome
5- function translate ( obj , parentKey = '' ) {
6+ function translate ( obj : any , parentKey = '' ) : any {
67 const result = { }
78 if ( typeof obj === 'object' ) {
89 for ( const key in obj ) {
@@ -27,23 +28,25 @@ function translate (obj, parentKey = '') {
2728/**
2829 * The plugin to generate locale message files for browser
2930 */
30- class GenerateLocaleForChrome {
31+ class GenerateLocaleForChrome implements webpack . WebpackPluginInstance {
32+ outputFileName : string
33+ outputFileImport : string
3134 /**
3235 * @param {* } name the file name to generate
3336 * @param {* } importFile
3437 */
35- constructor ( name , importFile ) {
38+ constructor ( name : string , importFile : string ) {
3639 this . outputFileName = `generate_locale_messages_for_chrome_${ name } `
3740 this . outputFileImport = importFile
3841 }
39- async apply ( compiler ) {
42+ async apply ( compiler : webpack . Compiler ) {
4043 const options = compiler . options
4144 options . entry [ this . outputFileName ] = { import : [ this . outputFileImport ] }
4245 const outputPath = options . output . path
4346 const outFilePath = path . join ( outputPath , `${ this . outputFileName } .js` )
4447 compiler . hooks . done . tap ( 'GenerateLocaleForChromePlugin' , ( ) => {
4548 require ( outFilePath )
46- const messages = global . exportsToChrome
49+ const messages = ( global as any ) . exportsToChrome
4750 for ( const localeName in messages ) {
4851 // .e.g
4952 // {
@@ -68,4 +71,4 @@ class GenerateLocaleForChrome {
6871 }
6972}
7073
71- module . exports = GenerateLocaleForChrome
74+ export default GenerateLocaleForChrome
0 commit comments