We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
版本: "vite": "4.3.9", "@types/node": "20.3.1", "@types/react": "18.2.8", "@types/react-dom": "18.2.4", "vite-plugin-html": "^3.2.0"
vite.config.ts配置: plugins: [ react(), createHtmlPlugin({ entry: 'src/main.tsx', inject:{ data:{ injectScript:<script src="./inject.js"></script> }, tags: [ { injectTo: 'body-prepend', tag: 'div', attrs: { id: 'tag', }, }, ], } }), ], index.html中使用: <%- injectScript %>
<script src="./inject.js"></script>
本地dev时出现错误:
import { ErrorOverlay } from '/@vite/client' document.body.appendChild(new ErrorOverlay({"message":"ejs:8\n 6| \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\r\n 7| \u003ctitle>人才档案\u003c/title>\r\n >> 8| \u003c%- injectScript %>\r\n 9| \r\n 10| \u003c/head>\r\n 11| \u003cbody>\r\n\ninjectScript is not defined","stack":" at eval (eval at compile (D:\\reactProject\\talents-profile\\node_modules\\.pnpm\\[email protected]\\node_modules\\ejs\\lib\\ejs.js:673:12), \u003canonymous>:12:17)\n at anonymous (D:\\reactProject\\talents-profile\\node_modules\\.pnpm\\[email protected]\\node_modules\\ejs\\lib\\ejs.js:703:17)\n at Object.exports.render (D:\\reactProject\\talents-profile\\node_modules\\.pnpm\\[email protected]\\node_modules\\ejs\\lib\\ejs.js:425:37)\n at renderHtml (D:\\reactProject\\talents-profile\\node_modules\\.pnpm\\[email protected][email protected]\\node_modules\\vite-plugin-html\\dist\\index.cjs:232:26)\n at transform (D:\\reactProject\\talents-profile\\node_modules\\.pnpm\\[email protected][email protected]\\node_modules\\vite-plugin-html\\dist\\index.cjs:154:29)\n at applyHtmlTransforms (file:///D:/reactProject/talents-profile/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:37683:27)\n at async viteIndexHtmlMiddleware (file:///D:/reactProject/talents-profile/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:61791:28)","frame":""})) </script> </head> <body></body>
The text was updated successfully, but these errors were encountered:
injectScript: '<script src="./inject.js"></script>'
Sorry, something went wrong.
No branches or pull requests
版本:
"vite": "4.3.9",
"@types/node": "20.3.1",
"@types/react": "18.2.8",
"@types/react-dom": "18.2.4",
"vite-plugin-html": "^3.2.0"
vite.config.ts配置:
plugins: [
react(),
createHtmlPlugin({
entry: 'src/main.tsx',
inject:{
data:{
injectScript:
<script src="./inject.js"></script>
},
tags: [
{
injectTo: 'body-prepend',
tag: 'div',
attrs: {
id: 'tag',
},
},
],
}
}),
],
index.html中使用:
<%- injectScript %>
本地dev时出现错误:
<title>Error</title> <script type="module">The text was updated successfully, but these errors were encountered: