-
I'm really curious about the nomodule/module approach along with bugfixes release for preset-env. Yet I'm kind of struggling to setup a basic project with it. I can include the latest and greatest with type="module", yet I'm being plagued with setting up the regeneratorRuntime not found issue. It seems like I'm missing something obvious with @babel/runtime or something. But I'm not able to build and load two bundle, one for ie 11, another modern browser. https://github.com/JackHowa/esmodule-no-module-doing-something Does any one have good examples of the config? I've tried regenerator runtime plugins as well as just trying to search for the config on github |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 18 replies
-
The config looks correct 🤔 Are |
Beta Was this translation helpful? Give feedback.
-
Big thank you to @nicolo-ribaudo for debugging with me and for the patience. Also thanks to @developit for inspiring exploration and soon-to-be work work using nomodule/module approach. Overall, IE 11 with corejs and nomodule support mvp: https://github.com/JackHowa/esmodule-no-module-doing-something/releases/tag/v1.0.0 // legacy-webpack.config.js
const path = require('path');
module.exports = {
mode: 'production',
// prevents arrow funcs via
// https://webpack.js.org/migrate/5/#need-to-support-an-older-browser-like-ie-11
target: ['web', 'es5'],
entry: './app.js',
output: {
filename: 'app.legacy.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.m?js$/,
// don't transpile regenerator-runtime
exclude: [/regenerator-runtime/, /core-js/],
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
edge: '14',
ie: '11',
firefox: '52',
chrome: '43',
safari: '9',
},
useBuiltIns: 'usage',
corejs: 3
},
],
],
// installs regenerator-runtime
// ignored for transpilation
// needs dep @babel/runtime
plugins: ['@babel/plugin-transform-runtime'],
}
}
}
]
}
}; // modern-webpack.config.js
const path = require('path');
module.exports = {
mode: 'production',
entry: './app.js',
output: {
filename: 'app.modern.mjs',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: [/regenerator-runtime/],
use: {
loader: 'babel-loader',
options: {
presets: [
[
"@babel/preset-env",
{
"targets": {
"esmodules": true
},
"bugfixes": true
}
],
],
plugins: ['@babel/plugin-transform-runtime']
}
}
}
]
}
}; "scripts": {
"build:legacy:webpack": "webpack --config legacy-webpack.config.js",
"build:modern": "webpack --config modern-webpack.config.js",
"build:legacy": "babel app.js --config-file ./babel-legacy.config.json --out-file ./dist/app.legacy.js",
"build": "npm run build:modern && npm run build:legacy:webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JackHowa/esmodule-no-module-doing-something.git"
},
"keywords": [
"esmodules",
"nomodule",
"module",
"mjs",
"babel",
"plugin-transform-runtime"
],
"author": "jackhowa",
"license": "MIT",
"bugs": {
"url": "https://github.com/JackHowa/esmodule-no-module-doing-something/issues"
},
"homepage": "https://github.com/JackHowa/esmodule-no-module-doing-something#readme",
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"babel-loader": "^8.2.2",
"webpack": "^5.12.0",
"webpack-cli": "^4.3.1"
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"core-js": "^3.8.2"
}
<script type="module" src="dist/app.modern.mjs"></script>
<script nomodule defer src="dist/app.legacy.js"></script> Open to feedback on editing this if necessary. Full repo https://github.com/JackHowa/esmodule-no-module-doing-something |
Beta Was this translation helpful? Give feedback.
Big thank you to @nicolo-ribaudo for debugging with me and for the patience. Also thanks to @developit for inspiring exploration and soon-to-be work work using nomodule/module approach.
Overall, IE 11 with corejs and nomodule support mvp: https://github.com/JackHowa/esmodule-no-module-doing-something/releases/tag/v1.0.0