Pkg: Module aliases

Created on 29 Sep 2017  路  10Comments  路  Source: vercel/pkg

It would be great if the integrated bundler could resolve aliases (or even just map ~ to a base directory like fuse-box).

Most helpful comment

This issue will be addressed soon. Meanwhile please use transpilation step with babel-plugin-module-alias. Pkg and babel preserve files, thus preserve correct stacktraces. Unlike browserify.

All 10 comments

Can you give exact example of desired behavior. So that it works in node, but does not work with pkg.

For instance, with node, I can use the module-alias package, with fuse-box, there's a default alias '~' for the base dir of the sources, and with webpack there is resolve.alias.

I can't see a way to do this with pkg.

I'm using browserify to create a bundle and then make the executable with pkg using only the bundle. With browserify you have some tools to module alias, for example https://github.com/joeybaker/remapify, https://github.com/benbria/aliasify. Don't know if module-alias will work directly with browserify - maybe yes. The way i'm using browserify & pkg is as follows:

browserify myappindex.js --no-bundle-external  --no-builtins  -o bundle.js
pkg -t node8-linux -c pkg.json -o execfile bundle.js

hope this helps

@cancerberoSgx I understand that, but my point is that pkg already tries to do the bundling and if you look into the dictionary, there is a lot of special handling for specific modules. You won't get that if you bundle with browserify or webpack beforehand.

But the bundling done by pkt is not configurable, so it would be great to support aliases as a small additional feature.

@mika-fischer , thanks! Although I'm not getting it. For example, https://github.com/zeit/pkg/blob/master/dictionary/node-sass.js . What's the meaning of that? My question now would be, what are the things that pkg bundling can do that browserify cannot? I'm very comfortable bundling with the later before pkg and I want to know if I'm missing something.

I understand your point that since pkg promise to handle bundling, this is an issue / enhancement.

My comment was more a suggestion to pkg authors: remove bundling responsibility from pkg and delegate it to browserify since it works better, is well known, and has LOTS of utilities / plugins / transformations. pkg should only be responsible of packaging a bundle into an executable (unix philosophy) : latest node.js, more architectures, better packaging so we can use upx or strip that currently dont work. Of course this is a personal opinion.

This issue will be addressed soon. Meanwhile please use transpilation step with babel-plugin-module-alias. Pkg and babel preserve files, thus preserve correct stacktraces. Unlike browserify.

I would love to see this happening.

I would like to contribute on this, but I have trouble in finding module resolution code. Could anyone please tell me where to look at?

Also in the need of this feature. Would also be willing to add it.

Hey everybody.

Did a bit of research and found that you can use ef-tspm to revert the module aliases made using typescript.

Had an issue with zeit/pkg because the generated files (in the dist folder) still had the @/dir/to/your/file references, which pkg could not handle.

In case you need to change these back into their ../../../ form, you can use ef-tspm to bring it back. Note, if you do so, you won't need to deal with the extra steps for the module-alias specified above. Trade-off is you have an additional build step. So first you would tsc to build the typescript code, then ef-tspm to properly remove the module aliases.

Reference.


  1. npm install -D ef-tspm
  2. tsc
  3. ef-tspm
  4. pkg .
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Araknos picture Araknos  路  4Comments

hellower picture hellower  路  3Comments

peterjwest picture peterjwest  路  3Comments

jflayhart picture jflayhart  路  4Comments

Admiral-Enigma picture Admiral-Enigma  路  3Comments