Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

migrate to @mrhenry/core-web #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,33 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>core-web Example</title>

<script src="./bundle.js"></script>
<!-- Ensure that older Safari doesn't load both bundles -->
<script nomodule>
(function () {
try {
var check = document.createElement('script');
if (!('noModule' in check) && 'onbeforeload' in check) {
var support = false;
document.addEventListener('beforeload', function (e) {
if (e.target === check) {
support = true;
} else if (!e.target.hasAttribute('nomodule') || !support) {
return;
}
e.preventDefault();
}, true);
check.type = 'module';
check.src = '.';
document.head.appendChild(check);
check.remove();
}
} catch (_) {
}
}());
</script>

<script type="module" src="./bundle.modules.js"></script>
<script nomodule src="./bundle.nomodules.js"></script>
</head>
<body>
loading...
Expand Down
94 changes: 94 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.8",
"@mrhenry/babel-plugin-core-web": "^1.0.0",
"babel-loader": "^9.0.0",
"core-js": "^3.16.0",
"webpack": "^5.47.1",
Expand Down
184 changes: 179 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,209 @@
module.exports = [
// Modules
{
mode: 'production',
output: {
filename: 'bundle.js'
filename: 'bundle.modules.js'
},
target: [
'web',
// Browsers with modules support
'browserslist:Opera 48 or Safari 10.1 or Chrome 61 or Edge 16 or Firefox 60'
],
optimization: {
minimize: true,
},
module: {
rules: [
{
// Second stage to polyfill ES features in core-web
test: /\.js$/,
include: /(core-web\/modules|core-web\/helpers)/,
use: {
loader: 'babel-loader',
options: {
comments: false,
presets: [
[
'@babel/preset-env',
{
corejs: '^3.6.3',
bugfixes: true,
targets: {
// Browsers with modules support
browsers: [
"Opera >= 48",
"Safari >= 10.1",
"Chrome >= 61",
"Edge >= 16",
"Firefox >= 60"
]
},
useBuiltIns: 'usage',
exclude: [
"web.dom-collections.iterator",
"web.dom-collections.for-each"
]
}
]
]
}
}
},
{
// First stage to polyfill your own code
test: /\.js$/,
exclude: /(node_modules|core-web\/modules|core-web\/helpers)/,
use: {
loader: 'babel-loader',
options: {
comments: false,
plugins: [
[
'@mrhenry/core-web',
{
// Browsers with modules support
browsers: {
"opera": "48",
"safari": "10.1",
"chrome": "61",
"edge": "16",
"firefox": "60"
},
debug: true
}
]
],
presets: [
[
'@babel/preset-env',
{
corejs: '^3.6.3',
bugfixes: true,
targets: {
// Browsers with modules support
browsers: [
"Opera >= 48",
"Safari >= 10.1",
"Chrome >= 61",
"Edge >= 16",
"Firefox >= 60"
]
},
useBuiltIns: 'usage',
exclude: [
"web.dom-collections.iterator",
"web.dom-collections.for-each"
]
}
]
]
}
}
}
]
}
},

// No Modules
{
mode: 'production',
output: {
filename: 'bundle.nomodules.js'
},
target: [
'web',
// IMPORTANT : You can change this config. Choose the oldest browsers you want to support
'browserslist:> 0.25%, not dead'
'browserslist:IE 8 or Opera 12 or Safari 5 or Chrome 15 or Edge 12 or Firefox 4'
],
optimization: {
minimize: true
},
module: {
rules: [
{
// Second stage to polyfill ES features in core-web
test: /\.js$/,
include: /(core-web\/modules|core-web\/helpers)/,
use: {
loader: 'babel-loader',
options: {
comments: false,
presets: [
[
'@babel/preset-env',
{
corejs: '^3.6.3',
bugfixes: true,
targets: {
// IMPORTANT : You can change this config. Choose the oldest browsers you want to support
browsers: [
"IE >= 8",
"Opera >= 12",
"Safari >= 5.1",
"Chrome >= 15",
"Edge >= 12",
"Firefox >= 4"
]
},
useBuiltIns: 'usage',
exclude: [
"web.dom-collections.iterator",
"web.dom-collections.for-each"
]
}
]
]
}
}
},
{
// First stage to polyfill your own code
test: /\.js$/,
exclude: /(node_modules)/,
exclude: /(node_modules|core-web\/modules|core-web\/helpers)/,
use: {
loader: 'babel-loader',
options: {
comments: false,
plugins: [
[
'@mrhenry/core-web',
{
// IMPORTANT : You can change this config. Choose the oldest browsers you want to support
browsers: {
"ie": "8",
"opera": "12",
"safari": "5.1",
"chrome": "15",
"edge": "12",
"firefox": "4"
},
debug: true
}
]
],
presets: [
[
'@babel/preset-env',
{
corejs: '^3.6.3',
bugfixes: true,
targets: "> 0.25%, not dead",
useBuiltIns: 'usage'
targets: {
// IMPORTANT : You can change this config. Choose the oldest browsers you want to support
browsers: [
"IE >= 8",
"Opera >= 12",
"Safari >= 5.1",
"Chrome >= 15",
"Edge >= 12",
"Firefox >= 4"
]
},
useBuiltIns: 'usage',
exclude: [
"web.dom-collections.iterator",
"web.dom-collections.for-each"
]
}
]
]
Expand Down