-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
RFC: Import glob tokens #125
Comments
I'm into this being static. I'm confused about the call to token there, where it does not have any interpolations, wouldn't token get called with only Could something like this work?: import {token} from 'parcel-bundler'
function loadRoute (name) {
return import(token`./routes/${name}/index.js`)
} or import {token} from 'parcel-bundler'
const route = token('./routes/*/index.js')
function loadRoute (name) {
return import(route(name))
} |
^ 😃 |
Parcel actually already supports glob imports: // import an object listing all the routes
import routes from './routes/*/index.js';
// access one
console.log(routes.blog); Don't think dynamic imports would work the way you might expect here though. |
I think the hope here is to avoid an unwanted glob import, if I understand correctly. For someone who wants to import the price of const dataSources = ['dog', 'cheese', 'foxhound']
const data = Promise.all(dataSources.map(source => import(`./data/${source}/price.js`))) And for Parcel to avoid bundling every other file on the system that matches In this case, static analysis would tell you that you only needed to bundle |
Would there be a fallback to the Webpack strategy (glob + grab everything), if somehow the path was not able to be statically inferred? for instance: function loadAlarmBells () {
return import(`./src/${window.library}`)
} |
No, that's exactly what I want to avoid. You must be explicit about what is included in the import.
I'm not sure it should support globs like that. Using dynamic imports where you load one at a time is better for apps and follows the spec
I'm not sure what you mean. |
i'm unsure about the intermediary if the user does |
I need this feature to be able to use parcel in one larger code base I am working on! Happy to find that you are discussing it 👍 The proposed solution would require importing parcel code into my production code base. I am a bit hesitant to that. I think build configuration and production code should be separated. For my specific use case I would prefer the way webpack handles this: including "everything". How common is having symlinks in a code base? |
There seem to be some many developers interested in this functionality |
Hit this issue today. I am trying to give parcel a try by migrating our app from Webpack. Our app loads the router during runtime
It would be great if this is somehow supported without glob imports. |
Would love if dynamic import is supported. I'm running into this issue when building a blog with MDX import { lazy, Suspense } from "react";
import { useParams } from "react-router-dom";
export default function BlogDetail() {
const { postId } = useParams();
const Post = lazy(() => import(`~src/blogs/${postId}.mdx`));
return (
<Suspense fallback={<div>Loading...</div>}>
<Post />
</Suspense>
);
} |
@devongovett I have tried it but still not working, it said Might be it is caused by invoking at run-time 🤔 |
I think a solution similar to webpack's magic annotation is best, or the token method as mentioned above. webpack style: const search = React.useMemo(() => {
const module = import(
/* webpackInclude: /engine\.ts$/ */
/* webpackMode: "lazy" */
`@/component/Dictionaries/${dictId}/engine.ts`
);
console.log(module);
}, [dictId]); token style: import {token} from 'parcel-bundler'
function loadRoute (name) {
return import(token`./routes/${name}/index.js`)
} |
Are there any updates on this issue? |
Webpack has the concept of require contexts which are (in my opinion) completely broken.
When you have a require expression like:
Webpack basically turns that into a regex which in glob form is:
Which is both the correct thing for it to do in that scenario and very very bad.
Instead of that, I would like to see something along the lines of:
This way we can statically extract out the path from the token and match it against the file system in a reasonable way.
We can also validate the import on the client when you call
token(glob)(url)
.import { token } from 'parcel-bundler';
avoids adding anything new to the languageThe text was updated successfully, but these errors were encountered: