Comments (5)
Your publicPathExpression
is set to /static/sig/
(without quotes), which is NOT a valid JS expression.
You shouldn't use /static/sig/
as publicPathExpression
, instead use a JS expression like window.publicPath
and assign to it on your <head>
:
<script>
window.publicPath = "http://cdn.your.site/static/sig/";
</script>
from vite-plugin-public-path.
Just refer to the test. In your HTML file:
vite-plugin-public-path/e2e/index.html
Lines 8 to 10 in 9ef47e7
If you public path is decided staticly in client side, just use a string literal expression here. If your server decides which CDN to use, replace a placeholder when serving the file like:
vite-plugin-public-path/e2e/e2e.test.ts
Lines 102 to 105 in 9ef47e7
from vite-plugin-public-path.
Also you can provide a minimum working example to reproduce your problem if you encountered one.
from vite-plugin-public-path.
Can you help to take a look?
Thank you so much
vite.config.js
base: process.env.NODE_ENV === "production" ? "/__vite_base__/" : "/",
plugins:[
react(),
publicPath({
// A JS expression evaluates on client side each time when loading a new file
// Should evaluate to a string ending with "/"
publicPathExpression: "/static/sig/",
// See below for explanation of `options.html`
html: true
}),
],
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
window.publicPath = __public_path__;
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
build error:
[vite-plugin-public-path] error: Unexpected token `<eof>`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier
--> <anon>:1:12
|
1 | /static/sig/
| ^
Caused by:
Syntax Error
error during build:
Error: error: Unexpected token `<eof>`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier
--> <anon>:1:12
|
1 | /static/sig/
from vite-plugin-public-path.
works in this way:
vite.config.js:
base: process.env.NODE_ENV === "production" ? "/__vite_base__/" : "/",
plugins:[
react(),
publicPath({
// A JS expression evaluates on client side each time when loading a new file
// Should evaluate to a string ending with "/"
publicPathExpression: "window.publicPath",
// See below for explanation of `options.html`
html: true
}),
],
indext.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
window.publicPath = "/static/sig/";
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Thank you so much
from vite-plugin-public-path.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-public-path.