Skip to content

Commit

Permalink
perf(bundled version): minify idna-map.js and rely on it as well
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Apr 29, 2022
1 parent e1c04f5 commit 0b0ffc9
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 37 deletions.
34 changes: 27 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const {dest, src, watch, series} = require('gulp');
const gulpEsbuild = require('gulp-esbuild');
const rename = require('gulp-rename');
const terser = require('gulp-terser');
const prettier = require('gulp-prettier');
const prettiercfg = require('./.prettierrc');
const filesForPrettier = ['test/*.js', '*.js', '.*.js', '!*.min.js'];
Expand All @@ -19,7 +21,7 @@ exports.prettierCheck = function () {
/**
* format code using prettier
*/
exports.prettier = function () {
exports.prettier = function prettify() {
return src(filesForPrettier)
.pipe(prettier(prettiercfg))
.pipe(dest(file => file.base));
Expand All @@ -28,8 +30,8 @@ exports.prettier = function () {
/**
* Esbuild minify + bundle css and js files
*/
exports.bundle = function () {
return src('./uts46.js')
exports.bundle = function bundle() {
return src('./uts46.min.js')
.pipe(
gulpEsbuild({
outfile: 'uts46bundle.min.js',
Expand All @@ -39,18 +41,36 @@ exports.bundle = function () {
platform: 'browser',
globalName: 'ispapiIdnconverter',
sourcemap: true,
target: 'es2015',
target: 'es2015', // ES6
resolveExtensions: ['.js'],
allowOverwrite: true,
}),
)
.pipe(dest('.'));
};

exports.minify = function minify() {
return src(['./idna-map.js', './uts46.js'])
.pipe(
terser({
ecma: 2015,
compress: true,
mangle: true,
}),
)
.pipe(
rename(function (path) {
path.basename += '.min';
}),
)
.pipe(dest('.'));
};

/**
* watch for any changes, minify + bundle + concatinate
* watch for any changes, minify + bundle + concatenate
*/

exports.watcher = function () {
watch('./uts46.js', series(exports.prettier, exports.bundle));
watch('./uts46.js', series(exports.prettier, exports.minify, exports.bundle));
};

exports.build = series(exports.minify, exports.bundle);
1 change: 1 addition & 0 deletions idna-map.min.js

Large diffs are not rendered by default.

107 changes: 85 additions & 22 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"gulp": "^4.0.2",
"gulp-esbuild": "^0.10.3",
"gulp-prettier": "^4.0.0",
"gulp-rename": "^2.0.0",
"gulp-terser": "^2.1.0",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier-config-xo": "^2.0.0",
Expand Down
6 changes: 4 additions & 2 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ const cfg = require('@hexonet/semantic-release-github-npm-config');
cfg.plugins.unshift([
'@semantic-release/exec',
{
prepareCmd: 'gulp bundle',
prepareCmd: 'gulp build',
},
]);
cfg.plugins = cfg.plugins.map(plugin => {
if (plugin[0] === '@semantic-release/git') {
plugin[1].assets.push(
'uts46.min.js',
'idna-map.min.js',
'uts46bundle.js',
'uts46bundle.min.js',
'package-lock.json', // can be removed when covered in semantic-release-github-npm-config
'uts46bundle.min.js.map',
);
}
return plugin;
Expand Down
4 changes: 2 additions & 2 deletions uts46.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// eslint-disable-next-line no-undef
if (typeof define === 'function' && define.amd) {
// eslint-disable-next-line no-undef
define(['punycode', './idna-map'], function (punycode, idnaMap) {
define(['punycode', './idna-map.min'], function (punycode, idnaMap) {
return factory(punycode, idnaMap);
});
} else if (typeof exports === 'object') {
// eslint-disable-next-line node/no-deprecated-api
module.exports = factory(require('punycode'), require('./idna-map'));
module.exports = factory(require('punycode'), require('./idna-map.min'));
} else {
root.uts46 = factory(root.punycode, root.idna_map);
}
Expand Down
1 change: 1 addition & 0 deletions uts46.min.js

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

2 changes: 1 addition & 1 deletion uts46bundle.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions uts46bundle.min.js.map

Large diffs are not rendered by default.

0 comments on commit 0b0ffc9

Please sign in to comment.