RFC: Import Map Support (draft) #74
Replies: 1 comment 1 reply
-
I think you'd get the most mileage out of JSON. All web-devs are going to be most familiar with it, and Go has really good built-in interfacing with JSON objects through marshalling/unmarshalling and encoding/decoding when needed. So you wont be scaring anyone off by making them have to learn some other specific language that isn't JSON, and you'll be a lot less likely to run into any headaches that haven't been encountered by another gopher. Plenty of benefit, both for users and maintainers, imo 😋
I'm not sure about there being conflicts (though I'd err towards expecting there to be, at least to begin with), but I would suggest the naming convention follow Ruby's with something akin to:
This also seems to follow the naming convention for es module URLs across different CDNs. Speaking of, you mentioned being able to configure which CDN to use.
At least in the CLI, you could have various other flags as well, such as:
|
Beta Was this translation helpful? Give feedback.
-
Background
In v0.3, we'd like to introduce import maps and remove the Node.js requirement.
While this simplifies the internals, the primary reason is to simplify deploys. Right now Bud applications don't fit within a single buildpack on Fly/Heroku/Vercel, they're a blend of Go and Node. In order to deploy a Bud app, you'll need to write your own Docker file. After v0.3, Bud should look and feel like a stock Go application. You'll still probably need a Procfile, but that's about it.
This was primarily inspired by the Rails 7 demo, where I first learned about import maps and realized you don't need Node anymore.
Goals
API
Configuration
The source of truth for import maps is in the configuration. Import maps are configured in Go files. Here's an idea of how this might work below:
(TODO: this section highly depends on the not-yet-written RFC: Env Support)
Open Questions
CLI
There should be some way to manage import maps from the CLI. This probably would come as a follow-up to the initial configuration-based release.
Something like:
Open Questions
go get
and import map installation underbud get
? Would there be conflicts? Are they separate concerns?uninstall
,upgrade
, etc.Usage
bud run
In general,
bud run
should behave similar to how the browser behaves, where a browser refresh will give you the latest content ever time.I think this means that our bundler will need to resolve remote imports per request and will use the import map to transform:
import { uniqBy } from 'lodash/uniqBy'
import { uniqBy } from 'https://cdn.jsdelivr.net/npm/lodash'
bud build
bud build
should pre-resolve, tree-shake, bundle and minify dependencies. This means it will resolve all dependencies during the build step. It should also prepare the assets for long-term caching (TBD).Long-Term Caching using Import Maps (maybe)
There's a way to rewrite file paths using import maps. This allows us not to require the user to pass around dynamic paths, but instead use import maps to rewrite file paths. See this clip for more details.
While surely simpler, it doesn't seem as flexible as something like Rail's asset_path because it doesn't support other assets like images.
Resources
Beta Was this translation helpful? Give feedback.
All reactions