Closed lydell closed 5 years ago
I don't think it's going to work. This code is supposed to run in the browser as well as on the server, and the 'url' package won't be available in the browser window. I think we should just revert your change from #12 and add the the missing features to parseUrl
. Could you do that instead of changing the build system?
I should have thought about it, my bad.
It does work, I’ve tried it!
I fixed the issue, actually it was just because of the config of webpack-node-externals.
Here is the commit: https://github.com/gvergnaud/nextjs-dynamic-routes/commit/c92f1ae7692a9a5caf7fc0e75c8cee6fa593652b
You can see the result here: https://bundlephobia.com/result?p=nextjs-dynamic-routes@2.5.1
I'm closing your PR, because I'd like to keep webpack for now.
Thanks!
Nice! Just curious – is there are reason you want to keep webpack? Not using it saves another 0.5kB :)
And both ways result in require("url")
in the built code.
It's just that the less diff in a PR/commit === the less potential bugs added :)
I made a mistake in #12 when saying this:
I forgot to run
npm run build
in this repo when testing the new bundle size, so my "before" and "after" results were identical! Doh!As you can see at bundlephobia, #12 did bump up the size of the package quite a lot (14 kB to 24 kB).
This happens because
dist/
is compiled using webpack, pulling all dependencies into the bundle.This commit fixes the problem by only using babel to compile
dist/
, leaving allrequire
calls intact, letting Next.js' build take care of resolving and bundling them. This lets Next.js share the same 'url' module both for itself and for this package.Size before this PR: 26.2 kB
![screenshot from 2019-01-25 08-09-54](https://user-images.githubusercontent.com/2142817/51731192-815d8700-207a-11e9-8449-483a669f8084.png)Size after this PR: 12.8 kB
![screenshot from 2019-01-25 08-15-58](https://user-images.githubusercontent.com/2142817/51731239-ab16ae00-207a-11e9-9716-cb0c7f385e5e.png) Also, "loose mode" was turned on in .babelrc since it saves 1.5 kB and we don't use any features that require the extra spec compliance anyway.