webpack-import-maps-loader

1.0.3 • Public • Published

webpack-import-maps-loader

Plugin to rewrite bare imports to URLs as defined in import map

Known limitations

Only dynamic imports supported at this time.

// Promise
import('user').then(({logout}) =>  logout());

// Using await
const { logout } = await import('user');

If you know how to get Webpack to ignore a regular import. Please get in touch!

Installation

$ npm install -D webpack-import-maps-loader

Usage

With module map inlined:

export default {
  // ...other webpack config
  module: {
    rules: [
      {
        test: /\.[tj]sx?$/,
        use: {
          loader: "webpack-import-maps-loader",
          options: {
            imports: {
              "bare-import": "https://assets.domain.tld/bare-import/index.js",
            },
          },
        },
      }
    ]
  }
};

Or loaded as a file:

// import-map.json
{
  "imports": {
    "bare-import": "https://assets.domain.tld/bare-import/index.js"
  }
}

// webpack.config.js
export default {
  module: {
    rules: [
      {
        test: /\.[tj]sx?$/,
        use: {
          loader: "webpack-import-maps-loader",
          options: require('./import-map.json'),
        },
      },
    ],
  },
};

Package Sidebar

Install

npm i webpack-import-maps-loader

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

3.3 kB

Total Files

3

Last publish

Collaborators

  • emilhauk