Comments (9)
@caoxiemeihao Here you will find the minimal repo: https://github.com/raphael-devel/raphael-devel-demo-sveltekit-repo-4-vite-plugin-dynamic-import
But it is really just a matter of:
npm create svelte@latest my-app
cd my-app
npm install
npm run dev
details about the SETUP you will find in README.md
Hope that helps..
For me this issue now is not crucial... but maybe it will help others...
from vite-plugin-dynamic-import.
vite.config.js
export default {
resolve: {
+ extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.svelte'],
},
}
https://github.com/vite-plugin/vite-plugin-dynamic-import/blob/v1.2.7/src/index.ts#L77
from vite-plugin-dynamic-import.
Is @library
an alias in your vite.config.js
?
from vite-plugin-dynamic-import.
in sveltekit the aliases are defined in the svelte.config.js
like so:
import adapter from '@sveltejs/adapter-auto';
import { mdsvex } from 'mdsvex';
import mdsvexConfig from './mdsvex.config.js';
import sveltePreprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: [
'.svelte',
...mdsvexConfig.extensions
],
preprocess: [
mdsvex(mdsvexConfig),
sveltePreprocess()
],
kit: {
adapter: adapter({ edge: true }),
alias: {
$library: 'src/library',
$content: 'src/content',
$images: 'src/images',
$music: 'src/music',
$themes: 'src/themes'
}
}
};
export default config;
...and sveltekit itself is a vite plugin, like so:
import { sveltekit } from '@sveltejs/kit/vite';
import autoImport from 'sveltekit-autoimport';
import dynamicImport from 'vite-plugin-dynamic-import';
import { imagetools } from 'vite-imagetools';
import mkcert from 'vite-plugin-mkcert';
/** @type {import('vite').UserConfig} */
const supportedExtensions = ['webp', 'jpg', 'jpeg', 'png'];
const config = {
ssr: {
noExternal: [
'svelte-stripe-js',
'style-value-types',
'popmotion',
'framesync'
]
},
plugins: [
autoImport({
components: ['./src/library'],
}),
sveltekit(),
dynamicImport(),
imagetools(
{
defaultDirectives: (url) => {
const extension = url.pathname.substring(
url.pathname.lastIndexOf('.') + 1
);
if (supportedExtensions.includes(extension)) {
return new URLSearchParams({
format: `webp;jpg`,
width: `200;300;400;500;800;1000;2000`,
picture: true
});
}
return new URLSearchParams();
}
},
),
mkcert({hosts: ['localhost', 'app.local']})
]
};
export default config;
...and those aliases defined in the `svelte.config.js file are used in the generated tsconfig.json, like so:
{
"compilerOptions": {
"baseUrl": "..",
"paths": {
"$library": [
"src/library"
],
"$library/*": [
"src/library/*"
],
"$content": [
"src/content"
],
"$content/*": [
"src/content/*"
],
"$images": [
"src/images"
],
"$images/*": [
"src/images/*"
],
"$music": [
"src/music"
],
"$music/*": [
"src/music/*"
],
"$themes": [
"src/themes"
],
"$themes/*": [
"src/themes/*"
]
},
"rootDirs": [
"..",
"./types"
],
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"preserveValueImports": true,
"lib": [
"esnext",
"DOM",
"DOM.Iterable"
],
"moduleResolution": "node",
"module": "esnext",
"target": "esnext"
},
"include": [
"ambient.d.ts",
"./types/**/$types.d.ts",
"../vite.config.ts",
"../src/**/*.js",
"../src/**/*.ts",
"../src/**/*.svelte",
"../src/**/*.js",
"../src/**/*.ts",
"../src/**/*.svelte",
"../tests/**/*.js",
"../tests/**/*.ts",
"../tests/**/*.svelte"
],
"exclude": [
"../node_modules/**",
"./[!ambient.d.ts]**"
]
}
...but beyond these files i don't know what's going on between Vite and Svelte Kit.
from vite-plugin-dynamic-import.
You may need to define the corresponding alias in vite.config.js
.
Not sure how work Vite and Svelte Kit. Can you provide a minimal reproduction Demo?
from vite-plugin-dynamic-import.
oh geeez…totally forgot to make a minrep, apologies…does it work now?
from vite-plugin-dynamic-import.
Still need to reproduce the Demo 😅
from vite-plugin-dynamic-import.
@idleberg is talking in this post:
https://stackoverflow.com/questions/69295473/svelte-sveltekit-dynamic-import-of-components-with-variable
about how he did get a similar plugin => The Rollup plugin @rollup/plugin-dynamic-import-vars to work with Svelte and Vite. So while the concept of this vite plugin seems to work, this does not yet work with sveltekit and vite.
Still Error Output from svelte:
Error while preprocessing /home/user/projects/exampleapp/src/routes/example/switchmepage/+page.svelte - Transform failed with 1 error:
/home/user/projects/exampleapp/src/routes/example/switchmepage/+page.svelte:29:28: ERROR: Expected string but found "`./src/${"
Any chance you get this done @caoxiemeihao ? Otherwise maybe a hint: This is known to not work with xyz would be nice.
How did you solve your issue until now @rchrdnsh ?
from vite-plugin-dynamic-import.
Anyone provide a minimal reproduction of the repo? Because I haven't used SvelteKit
yet. :(
from vite-plugin-dynamic-import.
Related Issues (20)
- Bare imports do not work in monorepos HOT 8
- Cannot find module 'vite-plugin-utils' or its corresponding type declarations. HOT 2
- Build error when using the plugin in Vite.config HOT 1
- How can I import from some package?
- when this method in node_modules HOT 8
- Internal server error: Cannot use 'import.meta' outside a module HOT 3
- when i use node_modules error will occur when starting HOT 3
- Source Maps and Line Numbers are not correct HOT 1
- Please add a LICENSE if you are okay with people using this plugin HOT 1
- Not working in Vue project HOT 1
- `// [vite-plugin-dynamic-import] runtime -S-` header missing in compiled source HOT 3
- Massive import size HOT 2
- [vite-plugin-dynamic-import] Generated runtime code has redundant judgment rules in some cases HOT 1
- The above dynamic import cannot be analyzed by Vite. HOT 5
- Dynamic import not working Windows HOT 1
- Failed to parse vite-plugin-federation HOT 1
- Imports don't work within defineAsyncComponent() in Vue 2/3 HOT 2
- [Feature Request] Import map support HOT 5
- dynamic import not include subfolder HOT 1
- re Disable dynamic import detection for one line or for whole project HOT 3
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-dynamic-import.