-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ernest
committed
Mar 4, 2022
1 parent
74f9fc0
commit b380d4b
Showing
13 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
HELLO= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
.DS_Store | ||
.cache | ||
public/* | ||
!public/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Setup | ||
|
||
1. Install package: | ||
|
||
```sh | ||
$ pnpm i -D @import-meta-env/unplugin | ||
$ pnpm i -D @import-meta-env/cli | ||
``` | ||
|
||
1. Register `import-meta-env` plugin: | ||
|
||
```js | ||
// webpack.config.js | ||
const importMetaEnv = require("@import-meta-env/unplugin"); | ||
module.exports = { | ||
// ... | ||
plugins: [ | ||
// ... | ||
importMetaEnv.webpack(), | ||
], | ||
}; | ||
``` | ||
|
||
1. List public environment variables under `.env.example`. | ||
|
||
``` | ||
# .env.example | ||
HELLO= | ||
``` | ||
|
||
1. Set environment variables: | ||
|
||
```sh | ||
$ export HELLO=import-meta-env | ||
``` | ||
|
||
1. Start dev server: | ||
|
||
```sh | ||
$ pnpm exec webpack --watch | ||
``` | ||
|
||
```sh | ||
$ serve dist -p 3000 | ||
``` | ||
|
||
1. Build production: | ||
|
||
```sh | ||
$ pnpm exec webpack | ||
``` | ||
|
||
1. Serve production: | ||
|
||
```sh | ||
$ pnpm exec import-meta-env --disposable | ||
$ pnpm exec serve dist | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!doctype html><html><head><meta charset="utf-8"><title>Webpack App</title><meta name="viewport" content="width=device-width,initial-scale=1"><script defer="defer" src="main.js"></script></head><body></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/******/ (() => { // webpackBootstrap | ||
var __webpack_exports__ = {}; | ||
document.querySelector("body").innerHTML = ` | ||
<h1>Hello: ${({"HELLO":"import-meta-env"}).HELLO}</h1> | ||
`; | ||
|
||
/******/ })() | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"private": true, | ||
"name": "cli-args-disposable-example", | ||
"scripts": { | ||
"dev:watch": "webpack --watch", | ||
"dev:start": "serve dist -p 3000", | ||
"dev": "rimraf bundle && cross-env HELLO=import-meta-env concurrently pnpm:dev:start pnpm:dev:watch", | ||
"build": "rimraf dist && webpack", | ||
"preview": "cross-env HELLO=import-meta-env import-meta-env --disposable && serve dist -p 4173" | ||
}, | ||
"devDependencies": { | ||
"@import-meta-env/cli": "workspace:*", | ||
"@import-meta-env/unplugin": "workspace:*", | ||
"concurrently": "7.0.0", | ||
"cross-env": "^7.0.3", | ||
"html-webpack-plugin": "^5.5.0", | ||
"rimraf": "^3.0.2", | ||
"serve": "^13.0.2", | ||
"webpack": "^5.69.1", | ||
"webpack-cli": "^4.9.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
document.querySelector("body").innerHTML = ` | ||
<h1>Hello: ${import.meta.env.HELLO}</h1> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
set -e | ||
|
||
# set up | ||
rm -rf dist | ||
|
||
# act | ||
pnpm exec webpack | ||
pnpm exec cross-env HELLO=import-meta-env import-meta-env --disposable | ||
|
||
# assert | ||
diff -r dist __fixtures__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const importMetaEnv = require("@import-meta-env/unplugin"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
|
||
module.exports = { | ||
plugins: [new HtmlWebpackPlugin(), importMetaEnv.webpack()], | ||
optimization: { | ||
// Make output files easier to read. | ||
minimize: false, | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.