Skip to content

Instantly share code, notes, and snippets.

@developit
Last active November 7, 2019 19:35
Show Gist options
  • Save developit/c8df0ec97fb8f88acc42e8f513ba3c9b to your computer and use it in GitHub Desktop.
Save developit/c8df0ec97fb8f88acc42e8f513ba3c9b to your computer and use it in GitHub Desktop.

native-url webpack demonstration

Normal Build: 13.4 kB

With native-url: 5.95 kB

(less than half the size)

The result is functionally equivalent in Node 7+ and all modern browsers (Chrome 61+, Firefox 60+, Safari 10+, Edge 16+ and anything else with ES Modules support).

package-lock.json
node_modules
dist
{
"name": "native-url-tests",
"version": "0.0.1",
"scripts": {
"build": "npm run -s build:without && npm run -s build:with && npm run -s sizes",
"build:without": "webpack src.js -p -o dist/without.js --silent",
"build:with": "webpack src.js -p -o dist/with.js --silent --resolve-alias url=native-url",
"sizes": "echo \"Normal Build: $(cat dist/without.js | wc -c | pretty-bytes)\" && echo \"With native-url: $(cat dist/with.js | wc -c | pretty-bytes)\"",
"start": "echo 'Normal build:' && node dist/without && echo 'With native-url' && node dist/with"
},
"devDependencies": {
"native-url": "^0.2.0",
"pretty-bytes-cli": "^2.0.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
}
}
//const { format, resolve, parse } = require('url');
import { format, resolve, parse } from 'url';
console.log(
format({ hostname: 'foo.com' })
);
console.log(
resolve('http://example.com/', '/one')
);
console.log(
parse('https://www.google.com/search?q=hello')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment