Skip to content
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

plugin request: Handle data:mime,<data> urls #125

Closed
2 tasks done
frank-dspeed opened this issue Dec 30, 2019 · 5 comments · Fixed by #150
Closed
2 tasks done

plugin request: Handle data:mime,<data> urls #125

frank-dspeed opened this issue Dec 30, 2019 · 5 comments · Fixed by #150

Comments

@frank-dspeed
Copy link
Contributor

frank-dspeed commented Dec 30, 2019

Request Checklist:

New Plugin Use Case

I would like to import code as a module from a data:{mime} declaration.

import 'data:text/javascript, console.log('Buhhh')'
import me from 'data:application/json, { "my": 'json''}
import('data:application/json, { "my": 'json''})

New Plugin Proposal

Perhaps @rollup/plugin-data-mime. The plugin could look like:

{
  resolveId(id) {
    if (isDataUrl(id)) {
      return id;
    }
    return null;
  },
  load(id) {
    if (isDataUrl(id)) {
      return getCodeFromDataUrl(id);
    }
    return null;
  }
}
@shellscape
Copy link
Collaborator

@frank-dspeed thanks for opening an issue here for this. I've updated your issue with the content from the original rollup/rollup issue. That's the better way to go, since plugin maintainers and contributors are more likely to take up the effort without the extra friction of referencing and parsing another issue (we're all operating here on limited, volunteered time and availability.)

@shellscape shellscape changed the title Handle data:mime,<data> urls plugin request: Handle data:mime,<data> urls Dec 30, 2019
@shellscape
Copy link
Collaborator

shellscape commented Dec 30, 2019

For reference, here's Node's documentation on this import approach https://nodejs.org/api/esm.html#esm_data_imports

Discussion about node's implementation nodejs/node#28614

The commit to Node including their method for parsing the data uri nodejs/node@9fd9efa#diff-a7c0a5f3e4fc8503fefebbe82071bc38

@shellscape
Copy link
Collaborator

shellscape commented Jan 4, 2020

I've begun work on this plugin in the plugin/data-uri branch.

@LarsDenBakker saw your comment on the webpack issue and thought this might interest you.

@LarsDenBakker
Copy link
Contributor

Indeed I need one as well, I ended up writing my own but it's good to standardize.

@frank-dspeed
Copy link
Contributor Author

@LarsDenBakker yes i need it also for my esm-loader module to support cross platform importScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants