Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 30, 2022
2 parents 4589fa9 + 1ec0176 commit ea65af0
Show file tree
Hide file tree
Showing 47 changed files with 688 additions and 350 deletions.
2 changes: 1 addition & 1 deletion docs/guide/build.md
Expand Up @@ -8,7 +8,7 @@ The production bundle assumes support for modern JavaScript. By default, Vite ta

- Chrome >=87
- Firefox >=78
- Safari >=13
- Safari >=14
- Edge >=88

You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`.
Expand Down
14 changes: 8 additions & 6 deletions docs/guide/env-and-mode.md
Expand Up @@ -120,20 +120,22 @@ VITE_APP_TITLE=My App
In your app, you can render the title using `import.meta.env.VITE_APP_TITLE`.
However, it is important to understand that **mode** is a wider concept than just development vs. production. A typical example is you may want to have a "staging" mode where it should have production-like behavior, but with slightly different env variables from production.
You can overwrite the default mode used for a command by passing the `--mode` option flag. For example, if you want to build your app for our hypothetical staging mode:
In some cases, you may want to run `vite build` with a different mode to render a different title. You can overwrite the default mode used for a command by passing the `--mode` option flag. For example, if you want to build your app for a staging mode:
```bash
vite build --mode staging
```
And to get the behavior we want, we need a `.env.staging` file:
And create a `.env.staging` file:
```
# .env.staging
NODE_ENV=production
VITE_APP_TITLE=My App (staging)
```
Now your staging app should have production-like behavior, but display a different title from production.
As `vite build` runs a production build by default, you can also change this and run a development build by using a different mode and `.env` file configuration:
```
# .env.testing
NODE_ENV=development
```
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@babel/types": "^7.20.5",
"@microsoft/api-extractor": "^7.33.6",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-typescript": "^10.0.1",
"@types/babel__core": "^7.1.20",
"@types/babel__standalone": "^7.1.4",
"@types/convert-source-map": "^1.5.2",
Expand Down Expand Up @@ -122,6 +122,11 @@
"peerDependencies": {
"postcss": "*"
}
},
"acorn-walk": {
"peerDependencies": {
"acorn": "*"
}
}
}
}
Expand Down
45 changes: 24 additions & 21 deletions packages/plugin-vue/README.md
Expand Up @@ -20,45 +20,48 @@ export interface Options {
include?: string | RegExp | (string | RegExp)[]
exclude?: string | RegExp | (string | RegExp)[]

ssr?: boolean
isProduction?: boolean

// options to pass on to vue/compiler-sfc
script?: Partial<Pick<SFCScriptCompileOptions, 'babelParserPlugins'>>
template?: Partial<
Pick<
SFCTemplateCompileOptions,
| 'compiler'
| 'compilerOptions'
| 'preprocessOptions'
| 'preprocessCustomRequire'
| 'transformAssetUrls'
>
>
style?: Partial<Pick<SFCStyleCompileOptions, 'trim'>>

/**
* Transform Vue SFCs into custom elements (requires vue@^3.2.0)
* - `true` -> all `*.vue` imports are converted into custom elements
* - `string | RegExp` -> matched files are converted into custom elements
* Transform Vue SFCs into custom elements.
* - `true`: all `*.vue` imports are converted into custom elements
* - `string | RegExp`: matched files are converted into custom elements
*
* @default /\.ce\.vue$/
*/
customElement?: boolean | string | RegExp | (string | RegExp)[]

/**
* Enable Vue reactivity transform (experimental, requires vue@^3.2.25).
* https://github.com/vuejs/core/tree/master/packages/reactivity-transform
*
* Enable Vue reactivity transform (experimental).
* https://vuejs.org/guide/extras/reactivity-transform.html
* - `true`: transform will be enabled for all vue,js(x),ts(x) files except
* those inside node_modules
* - `string | RegExp`: apply to vue + only matched files (will include
* node_modules, so specify directories in necessary)
* node_modules, so specify directories if necessary)
* - `false`: disable in all cases
*
* @default false
*/
reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]

// options to pass on to vue/compiler-sfc
script?: Partial<Pick<SFCScriptCompileOptions, 'babelParserPlugins'>>
template?: Partial<
Pick<
SFCTemplateCompileOptions,
| 'compiler'
| 'compilerOptions'
| 'preprocessOptions'
| 'preprocessCustomRequire'
| 'transformAssetUrls'
>
>
style?: Partial<Pick<SFCStyleCompileOptions, 'trim'>>
/**
* Use custom compiler-sfc instance. Can be used to force a specific version.
*/
compiler?: typeof _compiler
}
```

Expand Down
29 changes: 29 additions & 0 deletions packages/vite/LICENSE.md
Expand Up @@ -566,6 +566,35 @@ Repository: https://github.com/acornjs/acorn.git
---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Repository: https://github.com/acornjs/acorn.git

> MIT License
>
> Copyright (C) 2012-2020 by various contributors (see AUTHORS)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
---------------------------------------

## ansi-regex
License: MIT
By: Sindre Sorhus
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/package.json
Expand Up @@ -76,9 +76,10 @@
"@rollup/plugin-dynamic-import-vars": "^2.0.1",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-typescript": "^10.0.1",
"@rollup/pluginutils": "^5.0.2",
"acorn": "^8.8.1",
"acorn-walk": "^8.2.0",
"cac": "^6.7.14",
"chokidar": "^3.5.3",
"connect": "^3.7.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/vite/src/node/__tests__/env.spec.ts
Expand Up @@ -15,7 +15,6 @@ describe('loadEnv', () => {
"VITE_ENV1": "ENV1",
"VITE_ENV2": "ENV2",
"VITE_ENV3": "ENV3",
"VITE_USER_NODE_ENV": "production",
}
`)
})
Expand All @@ -36,14 +35,13 @@ describe('loadEnv', () => {
{
"VITE_APP_BASE_ROUTE": "/app/",
"VITE_APP_BASE_URL": "/app/",
"VITE_USER_NODE_ENV": "production",
}
`)
})

test('VITE_USER_NODE_ENV', () => {
loadEnv('development', join(__dirname, './env'))
expect(process.env.VITE_USER_NODE_ENV).toEqual('production')
expect(process.env.VITE_USER_NODE_ENV).toEqual(undefined)
})

test('Already exists VITE_USER_NODE_ENV', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/__tests__/env/.env.development
@@ -1,4 +1,3 @@
NODE_ENV=production
VITE_ENV1=ENV1
VITE_ENV2=ENV2
VITE_ENV3=ENV3
16 changes: 15 additions & 1 deletion packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
@@ -1,6 +1,10 @@
import { describe, expect, test } from 'vitest'
import type { ResolvedConfig, UserConfig } from '../../config'
import { resolveEsbuildTranspileOptions } from '../../plugins/esbuild'
import {
ESBuildTransformResult,
resolveEsbuildTranspileOptions,
transformWithEsbuild
} from '../../plugins/esbuild'

describe('resolveEsbuildTranspileOptions', () => {
test('resolve default', () => {
Expand Down Expand Up @@ -237,6 +241,16 @@ describe('resolveEsbuildTranspileOptions', () => {
})
})

describe('transformWithEsbuild', () => {
test('not throw on inline sourcemap', async () => {
const result = await transformWithEsbuild(`const foo = 'bar'`, '', {
sourcemap: 'inline'
})
expect(result?.code).toBeTruthy()
expect(result?.map).toBeTruthy()
})
})

/**
* Helper for `resolveEsbuildTranspileOptions` to created resolved config with types.
* Note: The function only uses `build.target`, `build.minify` and `esbuild` options.
Expand Down

0 comments on commit ea65af0

Please sign in to comment.