matthewp / babel-plugin-modules-web-compat

A Babel plugin that makes modules web compatible

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

babel-plugin-modules-web-compat

A Babel plugin that rewrites module specifiers to be web compatible.

For example, this code:

import { Component } from 'preact';
import * as util from './util';

Will be transformed into:

import { Component } from './node_modules/preact/dist/preact.js';
import * as util from './util/index.js';

Making it possible to load in browsers that support <script type="module">.

Install

yarn add babel-plugin-modules-web-compat --dev

Usage

In your .babelrc add:

{
  "plugins": [
    "modules-web-compat"
  ]
}

To prepare your modules for distribution to npm, it will need to resolve npm dependencies to the parent folder. Use packageResolutionStrategy to turn on this behavior:

{
  "plugins": [
    ["modules-web-compat", {
      "packageResolutionStrategy": "npm"
    }]
  ]
}

Which will add an addition ../ to your npm dependency specifiers.

License

BSD 2 Clause

About

A Babel plugin that makes modules web compatible


Languages

Language:JavaScript 100.0%