Skip to content

Commit 203035d

Browse files
authored
Merge pull request #9 from vite-plugin/v2.0.2
V2.0.2
2 parents 301f530 + 52079de commit 203035d

7 files changed

Lines changed: 18 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.0.2 (2023-06-23)
2+
3+
- 2ac2913 chore: remove useless files
4+
- af3128f feat: natives cache reuse
5+
- 8fcc3e9 chore: add comments
6+
- 39c1355 fix: filename typo
7+
18
## 2.0.1 (2023-06-20)
29

310
- f80f4c9 feat(test): add `better-sqlite3`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Supports Node/Electron C/C++ native addons. It is a bundle solution based on [We
77
[![NPM version](https://img.shields.io/npm/v/vite-plugin-native.svg)](https://npmjs.org/package/vite-plugin-native)
88
[![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-native.svg)](https://npmjs.org/package/vite-plugin-native)
99

10-
English | [简体中文](./README.zn-CN.md)
10+
English | [简体中文](./README.zh-CN.md)
1111

1212
## Install
1313

@@ -51,4 +51,4 @@ export interface NativeOptions {
5151

5252
> TODO: Translate into English.
5353
54-
See 👉🏻 [工作原理 (How to work)](./README.zn-CN.md#工作原理)
54+
See 👉🏻 [工作原理 (How to work)](./README.zh-CN.md#工作原理)
File renamed without changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-native",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Supports Node/Electron C/C++ native addons",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ const TAG = '[vite-plugin-native]'
2929
const loader1 = '@vercel/webpack-asset-relocator-loader'
3030
const NativeExt = '.native.cjs'
3131
const InteropExt = '.interop.mjs'
32+
// `nativesMap` is placed in the global scope and can be effective for multiple builds.
33+
const nativesMap = new Map<string, {
34+
built: boolean
35+
nativeFilename: string
36+
interopFilename: string
37+
}>
3238

3339
export default function native(options: NativeOptions): Plugin {
3440
const assetsDir = options.assetsDir ??= 'node_natives'
35-
const nativesMap = new Map<string, {
36-
built: boolean
37-
nativeFilename: string
38-
interopFilename: string
39-
}>
4041
// Webpack output(absolute path)
4142
let output: string
4243

@@ -125,6 +126,8 @@ function modifyAlias(config: UserConfig, aliases: Alias[]) {
125126
.reduce<Alias[]>((memo, [find, replacement]) => memo.concat({ find, replacement }), [])
126127
}
127128
const aliasArray = config.resolve.alias as Alias[]
129+
// Using Array.push can ensure that user config has a higher priority
130+
// @see https://github.com/rollup/plugins/blob/alias-v5.1.0/packages/alias/src/index.ts#L86
128131
aliasArray.push(...aliases)
129132
}
130133

test/fixtures/better-sqlite3.db

Whitespace-only changes.

test/fixtures/sqlite3.db

Whitespace-only changes.

0 commit comments

Comments
 (0)