-
-
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
Fix support for config.base
. Fix import.meta.url
being expanded. Fix use command instead of mode.
#4
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') { | ||
const source = fs.readFileSync(path.resolve(crateRoot, fileId)); | ||
const hash = createHash('md5').update(String(source)).digest('hex').substring(0, 8); | ||
const _name = config?.build?.assetsDir + '/' + path.basename(fileId).replace('.wasm', `.${hash}.wasm`); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We can't assume the base path to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, those are the changes from the latest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the build // 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)`); |
||
return code; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,4 +325,4 @@ function clearRswErrorOverlay() { | |
} | ||
|
||
window.createRswErrorOverlay = createRswErrorOverlay; | ||
`; | ||
`; |
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.
https://vitejs.dev/guide/api-plugin.html#configresolved