fix: parse error on define

This commit is contained in:
Simon Haugen 2021-04-22 18:09:45 +02:00
parent 15e91251ac
commit b4ab908ba2
3 changed files with 1029 additions and 948 deletions

1965
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"@types/react-dom": "^17.0.0",
"@vitejs/plugin-react-refresh": "^1.1.0",
"typescript": "^4.1.2",
"vite": "^2.0.0-beta.69",
"vite": "^2.2.0",
"vite-plugin-package-version": "file:.."
}
}

View File

@ -7,12 +7,10 @@ const createPlugin = (): Plugin => {
name: 'vite-plugin-package-version',
config: (_, env) => {
if (env) {
return {
define: {
['import.meta.env.PACKAGE_VERSION']:
process.env.npm_package_version,
},
};
const key = 'import.meta.env.PACKAGE_VERSION';
const val = JSON.stringify(process.env.npm_package_version);
return { define: { [key]: val } };
} else {
envInjectionFailed = true;
}