diff --git a/index.html b/index.html index 61c64f8..d09e6dd 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,33 @@ core-web Example - + + + + + loading... diff --git a/package-lock.json b/package-lock.json index 41774d2..c9e34b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,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", @@ -1591,6 +1592,56 @@ "@jridgewell/sourcemap-codec": "1.4.14" } }, + "node_modules/@mrhenry/babel-plugin-core-web": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@mrhenry/babel-plugin-core-web/-/babel-plugin-core-web-1.1.0.tgz", + "integrity": "sha512-Nh7cQX6Xe9wbctTEIXCkmefIaucgIFMFV4EiS/GB2XL44HNx80wwnRNf75nNup+o0/CO7D49eLgl4qarl4lDug==", + "dependencies": { + "@babel/helper-module-imports": "^7.15.4", + "@babel/types": "^7.18.13", + "@mrhenry/core-web": "^1.1.0", + "fast-deep-equal": "^3.1.3" + } + }, + "node_modules/@mrhenry/core-web": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@mrhenry/core-web/-/core-web-1.1.0.tgz", + "integrity": "sha512-QrL+ZzvcrlrKaROCP6ad1TSAVjY1/K3mkRQVYnSEv1VGZZ+vzetUKOwBXiETPIFbZCX156aO9utYcGGX87bKOw==", + "dependencies": { + "browserslist": "^4.21.5", + "semver": "^7.3.5" + } + }, + "node_modules/@mrhenry/core-web/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@mrhenry/core-web/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@mrhenry/core-web/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/@types/eslint": { "version": "8.21.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.21.2.tgz", @@ -4302,6 +4353,49 @@ "@jridgewell/sourcemap-codec": "1.4.14" } }, + "@mrhenry/babel-plugin-core-web": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@mrhenry/babel-plugin-core-web/-/babel-plugin-core-web-1.1.0.tgz", + "integrity": "sha512-Nh7cQX6Xe9wbctTEIXCkmefIaucgIFMFV4EiS/GB2XL44HNx80wwnRNf75nNup+o0/CO7D49eLgl4qarl4lDug==", + "requires": { + "@babel/helper-module-imports": "^7.15.4", + "@babel/types": "^7.18.13", + "@mrhenry/core-web": "^1.1.0", + "fast-deep-equal": "^3.1.3" + } + }, + "@mrhenry/core-web": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@mrhenry/core-web/-/core-web-1.1.0.tgz", + "integrity": "sha512-QrL+ZzvcrlrKaROCP6ad1TSAVjY1/K3mkRQVYnSEv1VGZZ+vzetUKOwBXiETPIFbZCX156aO9utYcGGX87bKOw==", + "requires": { + "browserslist": "^4.21.5", + "semver": "^7.3.5" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, "@types/eslint": { "version": "8.21.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.21.2.tgz", diff --git a/package.json b/package.json index e8b4cbc..2fe1bde 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/webpack.config.js b/webpack.config.js index ffc2e30..74b80a6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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" + ] } ] ]