Ignore some imports from vite:import-analysis
plugin to enable import-maps
workflow.
#6246
Unanswered
JayaKrishnaNamburu
asked this question in
Q&A
Replies: 3 comments 1 reply
-
I noticed that this question was asked in 2021. My situation and problem are the same as yours. How did you end up solving this problem? |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have the same problem. Help! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have written a plugin to solve similar problems, hoping to enlighten you plugins: [
// siyuan lib is actually empty and can only be loaded through require at run time.
// And vite using import will not be able to load to the change package, here do a hack to change to require
// In this way, with vite-plugin-siyuan, it can be directly referenced during development
{
name: "siyuan shim",
transform(code, id) {
if (/import \{(.*)\} from "siyuan"/.test(code)) {
const transformedCode = code.replace(
/import \{(.*)\} from "siyuan"/,
'const {$1} = require("siyuan")',
);
return {
code: transformedCode,
map: null,
};
}
},
},
], |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Heya, I am trying to setup a
import-maps
based worflow using vite. The main goal is to have the users code bundles usingvite
with all the HMR capabilities and stuff at build time. But load the dependencies alone from the CDN server.Errror
from here -> https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysis.ts#L203
In order for the deps to work, we set the
import-map
directly inside theindex.html
fileSo, in order to achieve the same. I am using the below config from vite
All, works good for
production
builds. But indev
mode, vite is runningvite:import-analysis
plugin to resolve the imported files. Is there is a way to by-pass thisimport-analysis
for specific files that are being defined inoptimizeDeps.exclude
. So the dev builds work in the same way as prod. And the deps are loaded using CDN.References
Vite setup
GitHub - https://github.com/JayaKrishnaNamburu/esm-vite-import-maps/blob/master/vite.config.ts
Deployed Vite App -> https://zealous-dubinsky-ed00ad.netlify.app/
Plain EsBuild setup
GitHub setup -> https://github.com/JayaKrishnaNamburu/esm-importmaps-esbuild-template/blob/master/builder.js#L29
Deployed version - https://serene-joliot-62d732.netlify.app
And i tried the same, with this cool plugin here https://github.com/pakholeung37/vite-plugin-import-maps. But still seems to break the build. Unless the module is inside script tag alone.
Beta Was this translation helpful? Give feedback.
All reactions