11ty / 11ty/eleventy-plugin-bundle
Inline local JS imports
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 83
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
Is it possible to configure a transform to inline the content of other local files imported from an included js chunk?
e.g.
// js/main.js
import env from '../_data/env.js';
// some js code that references env values
<!-- layouts/base.njk -->
...
<script type="module">{% include "js/main.js" %}</script>
...
When the bundles are processed, every page includes the main.js, which (at runtime, in the browser) tries to import _data/env.js and errors.
I've had a go at adding a transform to the .addBundle('js') call to use a bundler to inline imports, but of course they're being run against the final page path (eg /en/index.njk), so resolving paths is complex, and maybe this is the wrong place to be doing it?
Either way, it would be great if there was a quick way to handle local imports so config and constants can be shared around without needing to copy and paste. Have I missed something obvious?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the .addBundle('js') transform mentioned in the issue and trace how included chunks are processed against final page paths such as /en/index.njk. Compare that path handling with the local import in js/main.js and its dependency ../_data/env.js. Done means local imports are inlined when the bundle is included, without browser runtime import errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100