'Ignore module imports (ESM) webpack

I started studying webpack and I can't figure out how to ignore ESM modules (not embed them in a bundle)?

Read this, did as written, did not help.

...
<!-- index.html -->
<script src="dist/bundle.main.js">
<script src="dist/bundle.greeting.js" type="module">
...
// module/hello.mjs
export default class Hello{
  constructor(say){
    alert(say)
  }
}
// exted.js
import Hello from "./module/hello.mjs"
new Hello('ok');
// webpack.config.js
const path = require('path');

module.exports = {
  context: path.resolve(__dirname, './src/'),
  mode: 'development',
  entry: {
    main: './index.js',
    greeting: './extend.js'
  },
  output: {
    clean: true,
    filename: 'bundle.[name].js',
    path: path.resolve(__dirname, 'dist')
  } 
}

Result of importing into a bundle

// dist/bundle.greeting.js
...
new (class {
  constructor(e) {
    alert(e);
  }
})("ok")
...

Is it possible in the file bundle.greeting.js leave import... ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source