-
Notifications
You must be signed in to change notification settings - Fork 23
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
Automatically bundle dynamic import() #1093
Comments
Yeah, It would be super slick if steal would handle import similar to how webpack does. I think what webpack does is it scans files for If I use const config = route.data.configName;
import('config/${config}').then(config => {
}); webpack will automatically side bundle everything in config/....js as an individual bundle. |
Just an FYI, wildcards are supported in the bundle config now. |
To do this, you could probably search the ast for this and then update the bundle config. |
i am also not sure how to do this justin's suggestion looks valid for me so this could get added to steal tools maybe to scan for imports and modify bundle config.
|
We're going to turn this into a proposal. tldr; Make it so that steal-tools will automatically detect uses of
The ProblemIf you are creating a progressively loaded app you will likely split it into separate "pages", where each page is a separate bundle. So code like this: function switchPage(page) {
if(page === "cart") {
steal.import("~/cart/").then(mod => {
document.body.appendChild(new mod.Cart());
});
}
if(page === "home") {
steal.import("~/home/").then(mod => {
document.body.appendChild(new mod.Home());
});
}
} You will need to remember to update the {
"steal": {
"bundle": [
"~/cart/cart",
"~/home/home"
]
}
} Let's say you later add a new page, product. If you forget to add this to If you're using continuous deployment this becomes quite a big problem. The SolutionThe proposal is to add to steal-tools the ability to detect these |
Also consider the following: route.data.on('config', newConfig => {
import(`~/config/${newConfig}`).then(configModule => {
app.assign(configModule.default);
});
}); And the following directory structure:
Steal might detect each of these config files and side bundle them. Webpack does this sort of thing and it is surprisingly nice. For instance, webpack provides configuration in how to locate these modules by using special comments: function loadConfig(path) {
import(
/*
webpackMode: "lazy",
webpackInclude: /[A-z]+\.js(on)?/
*/
`./config/apps/${path}`
).then((config) => {
config = config.default;
const app = document.querySelector('dl-app');
if (app) {
document.body.removeChild(app);
}
document.body.appendChild(stache('<dl-app props="config" />')({config}));
});
} |
Steal should search for import() in ES6 code and bundle that stuff also
The text was updated successfully, but these errors were encountered: