swc-plugin-import-meta-env 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/package.json +38 -0
- package/swc_plugin_import_meta_env.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# swc-plugin-import-meta-env
|
|
2
|
+
|
|
3
|
+
> Simple plugin to transform `import.meta.env` to `process.env`
|
|
4
|
+
|
|
5
|
+
This `@swc` plugin provides a simple transformation from `import.meta.env` to `process.env`.
|
|
6
|
+
|
|
7
|
+
The original purpose of this was to allow `@swc` usage in a large Jest test suite while also using Vite for bundling.
|
|
8
|
+
|
|
9
|
+
## Install 🌱
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
npm i -D swc-plugin-import-meta
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage 🚀
|
|
16
|
+
|
|
17
|
+
Simply add this to the plugins field of your `.swcrc`.
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"jsc": {
|
|
22
|
+
"experimental": {
|
|
23
|
+
"plugins": [["swc-plugin-import-meta-env", {}]]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or programmatically as an extension to your existing `.swcrc` parsing:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const swcrc = JSON.parse(fs.readFileSync(".swcrc", "utf8"));
|
|
33
|
+
((swcrc.jsc ??= {}).experimental ??= {}).plugins = [
|
|
34
|
+
["swc-plugin-import-meta-env", {}],
|
|
35
|
+
]; // This may need updating to suit your requirements
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## How do I populate my environment? 🤔
|
|
39
|
+
|
|
40
|
+
The purpose of this plugin currently is to keep this transformation simple. There are many tools and utilities to load `.env` files into your environment already, such as performing this during your `setupTests` phase of testing.
|
|
41
|
+
|
|
42
|
+
- [`dotenv`](https://github.com/motdotla/dotenv)
|
|
43
|
+
- This is what [Vite itself uses to populate the env](https://vitejs.dev/guide/env-and-mode.html#env-files), so it makes sense to also do the same here.
|
|
44
|
+
|
|
45
|
+
If there is enough demand I can investigate adding this as core functionality to this plugin.
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swc-plugin-import-meta-env",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "@swc plugin for handling the transformation of import.meta.env",
|
|
5
|
+
"author": "Alex Miller <codex.nz@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/Codex-/swc-plugin-import-meta-env#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Codex-/swc-plugin-import-meta-env.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Codex-/swc-plugin-import-meta-env/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"swc-plugin",
|
|
17
|
+
"import.meta.env"
|
|
18
|
+
],
|
|
19
|
+
"main": "swc_plugin_import_meta_env.wasm",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"prepublishOnly": "cargo build-wasi --release",
|
|
22
|
+
"prepack": "cargo build-wasi --release && cp target/wasm32-wasi/release/swc_plugin_import_meta_env.wasm .",
|
|
23
|
+
"release": "release-it"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"swc_plugin_import_meta_env.wasm"
|
|
27
|
+
],
|
|
28
|
+
"preferUnplugged": true,
|
|
29
|
+
"packageManager": "pnpm@8.6.6",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@swc/core": "^1.3.68",
|
|
32
|
+
"auto-changelog": "^2.4.0",
|
|
33
|
+
"release-it": "^16.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@swc/core": "^1.3.68"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
Binary file
|