metro, metro-buck: preprend NODE_ENV variable to bundles

Reviewed By: rafeca

Differential Revision: D6674216

fbshipit-source-id: ca0d17f679eb8fb8dd4c50192836faaf02d1aba8
This commit is contained in:
Jean Lauliac 2018-01-08 10:56:28 -08:00 committed by Facebook Github Bot
parent fa8e1a6ea1
commit 521653798f
5 changed files with 20 additions and 3 deletions

View File

@ -66,6 +66,7 @@ exports.createBuildSetup = (
function prelude(optimize) {
return virtualModule(
`var __DEV__=${String(!optimize)},` +
'__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();',
'__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now(),' +
`process={env:{NODE_ENV:'${optimize ? 'production' : 'development'}'}};`,
);
}

View File

@ -35,7 +35,8 @@ describe('build setup', () => {
file: {
code:
'var __DEV__=true,__BUNDLE_START_TIME__=' +
'this.nativePerformanceNow?nativePerformanceNow():Date.now();',
'this.nativePerformanceNow?nativePerformanceNow():Date.now(),' +
"process={env:{NODE_ENV:'development'}};",
map: null,
path: '',
type: 'script',
@ -48,7 +49,8 @@ describe('build setup', () => {
const [prelude] = result.modules;
expect(prelude.file.code).toEqual(
'var __DEV__=false,__BUNDLE_START_TIME__=' +
'this.nativePerformanceNow?nativePerformanceNow():Date.now();',
'this.nativePerformanceNow?nativePerformanceNow():Date.now(),' +
"process={env:{NODE_ENV:'production'}};",
);
});

View File

@ -15,3 +15,5 @@ global.__DEV__ = false;
global.__BUNDLE_START_TIME__ = global.nativePerformanceNow
? global.nativePerformanceNow()
: Date.now();
global.process = {env: {NODE_ENV: 'production'}};

View File

@ -15,3 +15,5 @@ global.__DEV__ = true;
global.__BUNDLE_START_TIME__ = global.nativePerformanceNow
? global.nativePerformanceNow()
: Date.now();
global.process = {env: {NODE_ENV: 'development'}};

View File

@ -4,6 +4,11 @@ exports[`basic_bundle bundles package with polyfills 1`] = `
"(function (global) {
global.__DEV__ = false;
global.__BUNDLE_START_TIME__ = global.nativePerformanceNow ? global.nativePerformanceNow() : Date.now();
global.process = {
env: {
NODE_ENV: 'production'
}
};
})(this);
(function (global) {
'use strict';
@ -195,6 +200,11 @@ exports[`basic_bundle bundles package without polyfills 1`] = `
"(function (global) {
global.__DEV__ = false;
global.__BUNDLE_START_TIME__ = global.nativePerformanceNow ? global.nativePerformanceNow() : Date.now();
global.process = {
env: {
NODE_ENV: 'production'
}
};
})(this);
(function (global) {
'use strict';