]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: add __DEV__ global variable
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 12 Oct 2019 15:31:32 +0000 (17:31 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 12 Oct 2019 15:31:32 +0000 (17:31 +0200)
jest.config.js
rollup.config.js
src/global.d.ts [new file with mode: 0644]
tsconfig.json

index 7c39bcb9ed2b844ef9395fd6e83458d04a4b084b..74f91374226f2427d7aa63a28f1eb529898b3e9b 100644 (file)
@@ -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: ['<rootDir>/__tests__/**/*.spec.ts?(x)'],
   testEnvironment: 'node',
 }
index f771eca354c2786f029448092c901c51f9de49bd..a1b8222bf10799febb5f41779c37cee4face3286 100644 (file)
@@ -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 (file)
index 0000000..ca93dc0
--- /dev/null
@@ -0,0 +1,2 @@
+// Global compile-time constants
+declare var __DEV__: boolean
index 5a537c38ee405a8814b75babc15d3d6e61f385a9..5e768d79d3c0d35e1b54fc472b7270be52800c29 100644 (file)
@@ -1,5 +1,5 @@
 {
-  "include": ["src/**/*.ts", "__tests__/**/*.ts"],
+  "include": ["src/global.d.ts", "src/**/*.ts", "__tests__/**/*.ts"],
   "compilerOptions": {
     "target": "esnext",
     "module": "commonjs",