Snowpack: Feature Request: Babel plugin to automatically rewrite imports from "foobar" to "/web_modules/foobar.js"

Created on 28 Feb 2019  Â·  8Comments  Â·  Source: snowpackjs/snowpack

Would it be possible (or preferable) to automatically prepend "/web_modules" onto each import statement?

Most helpful comment

Done! If you install @pika/web v0.2.0 (latest) you can load it into your babelrc like so:

 {
  "plugins": [
    ["@pika/web/assets/babel-plugin.js"]
  ]
}

Still experimental, and might split it out into it's own package before v1, but that gets you want you need!

All 8 comments

Sure! We'd need to decide what's automatically doing the prepending, Babel?

Actually, it looks like this could work: https://www.npmjs.com/package/babel-plugin-bare-import-rewrite

{
    "plugins": [
        ["bare-import-rewrite", {
            "modulesDir": "/web_modules",
            "alwaysRootImport": ["**"]
        }]
    ]
}

Trying it out in a project now

How would that work when using both node_moduoes and web_modules?

Okay I tried out every babel plugin I could and no luck. I think we may just want to write one ourselves.

Done! If you install @pika/web v0.2.0 (latest) you can load it into your babelrc like so:

 {
  "plugins": [
    ["@pika/web/assets/babel-plugin.js"]
  ]
}

Still experimental, and might split it out into it's own package before v1, but that gets you want you need!

README updated as well

Awesome! What's the behavior if there's a conflict between node_modules and web_modules?

The plugin is super dumb for now, it just rewrites every "bare name" package import to it's web_modules/ file equivalent ¯\_(ツ)_/¯

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FredKSchott picture FredKSchott  Â·  5Comments

FredKSchott picture FredKSchott  Â·  6Comments

FredKSchott picture FredKSchott  Â·  6Comments

rvion picture rvion  Â·  6Comments

FredKSchott picture FredKSchott  Â·  6Comments