-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
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
Fix support for config.base
. Fix import.meta.url
being expanded. Fix use command instead of mode.
#4
Conversation
use command instead of mode.
@@ -41,7 +41,7 @@ export function ViteRsw(userOptions: RswPluginOptions): Plugin { | |||
const fileId = _path?.[1].replace(/^\//, '') + '_bg.wasm'; | |||
|
|||
// build wasm file | |||
if (!wasmMap.has(fileId) && config?.mode !== 'development') { | |||
if (!wasmMap.has(fileId) && config?.command !== 'serve') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -51,7 +51,7 @@ export function ViteRsw(userOptions: RswPluginOptions): Plugin { | |||
}); | |||
|
|||
// fix: fetch or URL | |||
code = loadWasm(code, path.basename(fileId), _name); | |||
code = loadWasm(code, path.basename(fileId), config.base + _name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume the base path to be /
. It could be anything. You can try with vite build --base "/custom/base/path"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, those are the changes from the latest tsup
release (4.8.21). Not sure how we can fix this on our side except sticking with 4.8.20 for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the build import.meta.url
will be replaced with __import_meta_url
// source code
code.replace(`new URL('${oPath}', import.meta.url)`, `new URL('${nPath}', location.origin)`)
// build
e.replace(`new URL('${o}', __import_meta_url)`,`new URL('${n}', location.origin)`)
solution: RegExp
// utils.ts
// ...
code = code.replace(/import\.meta\.url\.replace\(\/\\\.js\$\/, \'_bg\.wasm\'\);/, `fetch('${nPath}')`);
code = code.replace(`new URL('${oPath}',`, `new URL('${nPath}',`);
code = code.replace(/, import\.meta\.url\)/, `, location.origin)`);
@lencx I finally fixed it now, everything working fine. I've applied the RegEx just as you suggested which fixed all problems with Could you merge this? As a side note: Apparently this is a known problem: |
No description provided.