@@ -32,6 +32,21 @@ module.exports = (context, options = {}) => {
32
32
const plugins = [ ]
33
33
const defaultEntryFiles = JSON . parse ( process . env . VUE_CLI_ENTRY_FILES || '[]' )
34
34
35
+ // Though in the vue-cli repo, we only use the two envrionment variables
36
+ // for tests, users may have relied on them for some features,
37
+ // dropping them may break some projects.
38
+ // So in the following blocks we don't directly test the `NODE_ENV`.
39
+ // Rather, we turn it into the two commonly used feature flags.
40
+ if ( process . env . NODE_ENV === 'test' ) {
41
+ // Both Jest & Mocha set NODE_ENV to 'test'.
42
+ // And both requires the `node` target.
43
+ process . env . VUE_CLI_BABEL_TARGET_NODE = 'true'
44
+ // Jest runs without bundling so it needs this.
45
+ // With the node target, tree shaking is not a necessity,
46
+ // so we set it for maximum compatibility.
47
+ process . env . VUE_CLI_BABEL_TRANSPILE_MODULES = 'true'
48
+ }
49
+
35
50
// JSX
36
51
if ( options . jsx !== false ) {
37
52
presets . push ( [ require ( '@vue/babel-preset-jsx' ) , typeof options . jsx === 'object' ? options . jsx : { } ] )
@@ -134,8 +149,10 @@ module.exports = (context, options = {}) => {
134
149
// cli-plugin-jest sets this to true because Jest runs without bundling
135
150
if ( process . env . VUE_CLI_BABEL_TRANSPILE_MODULES ) {
136
151
envOptions . modules = 'commonjs'
137
- // necessary for dynamic import to work in tests
138
- plugins . push ( require ( 'babel-plugin-dynamic-import-node' ) )
152
+ if ( process . env . VUE_CLI_BABEL_TARGET_NODE ) {
153
+ // necessary for dynamic import to work in tests
154
+ plugins . push ( require ( 'babel-plugin-dynamic-import-node' ) )
155
+ }
139
156
}
140
157
141
158
// pass options along to babel-preset-env
0 commit comments