Skip to content

Commit

Permalink
refactor: remove __DEV__
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `__DEV__` magic flag has been removed
  • Loading branch information
yyx990803 committed Jun 19, 2020
1 parent a0eea2f commit e6182c3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 24 deletions.
4 changes: 0 additions & 4 deletions playground/App.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<template>
<h1>Vite Playground</h1>
<p class="dev">
<code>__DEV__: {{ dev }}</code>
</p>
<p class="base">
<code>process.env.BASE_URL: {{ base }}</code>
</p>
Expand Down Expand Up @@ -57,7 +54,6 @@ import TestDynamicImport from './dynamic-import/TestDynamicImport.vue'
export default {
data: () => ({
dev: __DEV__,
base: process.env.BASE_URL
}),
components: {
Expand Down
3 changes: 3 additions & 0 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// replaced by serverPluginHmr when served
declare const __SW_ENABLED__: boolean

// This file runs in the browser.
import { HMRRuntime } from 'vue'

Expand Down
6 changes: 3 additions & 3 deletions src/client/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare const __DEV__: boolean
declare const __BASE__: string
declare const __SW_ENABLED__: boolean
declare interface ImportMeta {
env: Record<string, string>
}
4 changes: 1 addition & 3 deletions src/client/vueJsxCompat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createVNode, isVNode } from 'vue'

declare const __DEV__: boolean

if (__DEV__) {
if (import.meta.env.MODE === 'development') {
console.log(
`[vue tip] You are using an non-optimized version of Vue 3 JSX, ` +
`which does not take advantage of Vue 3's runtime fast paths. An improved ` +
Expand Down
11 changes: 0 additions & 11 deletions src/node/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,6 @@ export async function build(options: BuildConfig): Promise<BuildResult> {
},
sourcemap
),
// for vite spcific replacements, make sure to only apply them to
// non-dependency code to avoid collision (e.g. #224 antd has __DEV__)
createReplacePlugin(
(id) =>
id.startsWith('/vite') ||
(!id.includes('node_modules') && /\.(j|t)sx?$/.test(id)),
{
__DEV__: `false`
},
sourcemap
),
// vite:css
createBuildCssPlugin({
root,
Expand Down
3 changes: 1 addition & 2 deletions src/node/server/serverPluginHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ export const htmlRewritePlugin: ServerPlugin = ({
resolver,
config
}) => {
// inject __DEV__ and process.env.NODE_ENV flags
// inject process.env flags
// since some ESM builds expect these to be replaced by the bundler
const { env = {}, mode } = config

const devInjectionCode =
`\n<script type="module">\n` +
`import "${hmrClientPublicPath}"\n` +
`window.__DEV__ = true\n` +
`window.process = { env: ${JSON.stringify({
...env,
NODE_ENV: mode,
Expand Down
1 change: 0 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('vite', () => {
})

test('env variables', async () => {
expect(await getText('.dev')).toMatch(`__DEV__: ${!isBuild}`)
expect(await getText('.base')).toMatch(`process.env.BASE_URL: /`)
expect(await getText('.node-env')).toMatch(
`process.env.NODE_ENV: ${isBuild ? 'production' : 'development'}`
Expand Down

0 comments on commit e6182c3

Please sign in to comment.