-
-
Save AWolf81/edb0872c1cb8b4e96ec4bfbf2f15fc22 to your computer and use it in GitHub Desktop.
Demo for injecting the version from package.json with Snowpack
This file contains hidden or 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
SNOWPACK_PUBLIC_SOME_OTHER_ENV=just a test |
This file contains hidden or 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
<!-- placed in public folder --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<script type="module" src="dist/index.js"></script> | |
</head> | |
<body> | |
%SNOWPACK_PUBLIC_VERSION% | |
<br/> | |
Snowpack plugin env loaded "someOtherEnv": | |
%SNOWPACK_PUBLIC_SOME_OTHER_ENV% | |
</body> | |
</html> |
This file contains hidden or 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
// placed in src folder | |
// you can use your version with import.meta | |
console.log(import.meta.env) |
This file contains hidden or 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
// plugin for injecting version from package.json | |
module.exports = () => { | |
return { | |
name: "inject-version", | |
async config() { | |
const {version} = require("./package.json") | |
process.env["SNOWPACK_PUBLIC_VERSION"] = version | |
} | |
} | |
} |
This file contains hidden or 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
/** @type {import("snowpack").SnowpackUserConfig } */ | |
module.exports = { | |
mount: { | |
public: {url: '/', static: true}, | |
src: {url: '/dist'}, | |
}, | |
plugins: [ | |
"@snowpack/plugin-dotenv", | |
"./inject-version" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment