gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

webpack NormalModuleReplacementPlugin with jest #136

Open gloriaJun opened 2 years ago

gloriaJun commented 2 years ago

webpack.config.js

new webpack.NormalModuleReplacementPlugin(/\.\/config-APPLICATION_PHASE/, `./config-${config.build.phase}`),

config dir

╰─❯ ls -al src/config 
total 64
drwxr-xr-x  10 user  staff  320  1 14 11:24 .
drwxr-xr-x  18 user  staff  576  1  4 21:01 ..
-rw-r--r--   1 user  staff  503  1 14 11:33 config-APPLICATION_PHASE.ts
-rw-r--r--   1 user  staff  981  1 14 11:24 config-BETA.js
-rw-r--r--   1 user  staff  220  1 14 11:24 config-LOCAL.js
-rw-r--r--   1 user  staff  830  1 14 11:24 config-REAL.js
-rw-r--r--   1 user  staff  209  1 14 11:24 index.ts

jest.config.js

to read phaseConfig on jest env

// jest.config.js
moduleNameMapper: {
    // ...SKIP...
    '^./config-APPLICATION_PHASE$': '<rootDir>/src/config/config-BETA',
},