From: Eduardo San Martin Morote Date: Sat, 12 Oct 2019 15:31:32 +0000 (+0200) Subject: chore: add __DEV__ global variable X-Git-Tag: v4.0.0-alpha.0~194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e58a2ceed8a1432a9503bb18bdb056680172da6;p=thirdparty%2Fvuejs%2Frouter.git chore: add __DEV__ global variable --- diff --git a/jest.config.js b/jest.config.js index 7c39bcb9..74f91374 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,10 @@ module.exports = { preset: 'ts-jest', + globals: { + __DEV__: true, + }, + coverageDirectory: 'coverage', + coverageReporters: ['html', 'lcov', 'text'], collectCoverageFrom: ['src/**/*.ts'], coveragePathIgnorePatterns: [ '/node_modules/', @@ -7,10 +12,6 @@ module.exports = { 'src/entries', 'src/consola.ts', ], - testMatch: [ - '**/__tests__/**/*.spec.ts?(x)', - // '**/__tests__/**/*.spec.[jt]s?(x)', - // '**/?(*.)+(spec|test).[jt]s?(x)', - ], + testMatch: ['/__tests__/**/*.spec.ts?(x)'], testEnvironment: 'node', } diff --git a/rollup.config.js b/rollup.config.js index f771eca3..a1b8222b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -32,13 +32,20 @@ function createEntry( ) { // force production mode when minifying if (minify) env = 'production' + const isProductionBuild = + process.env.__DEV__ === 'false' || env === 'production' + const isBundlerESMBuild = format === 'es' const config = { input, plugins: [ replace({ - __VERSION__: pkg.version, - 'process.env.NODE_ENV': `'${env}'`, + __VERSION__: JSON.stringify(pkg.version), + __DEV__: isBundlerESMBuild + ? // preserve to be handled by bundlers + `process.env.NODE_ENV !== 'production'` + : // hard coded dev/prod builds + !isProductionBuild, }), alias({ resolve: ['ts'], diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 00000000..ca93dc0d --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,2 @@ +// Global compile-time constants +declare var __DEV__: boolean diff --git a/tsconfig.json b/tsconfig.json index 5a537c38..5e768d79 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src/**/*.ts", "__tests__/**/*.ts"], + "include": ["src/global.d.ts", "src/**/*.ts", "__tests__/**/*.ts"], "compilerOptions": { "target": "esnext", "module": "commonjs",