webpack-import-maps-loader
v1.0.3
Published
Webpack loader for import maps
Downloads
19
Maintainers
Readme
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'),
},
},
],
},
};