electron-compile icon indicating copy to clipboard operation
electron-compile copied to clipboard

Allow compiling some of node_modules dependencies

Open mhagmajer opened this issue 7 years ago • 3 comments

We have a couple node dependencies that are published uncompiled. The logic behind it is to allow final projects to compile entire code in slightly different ways.

We're currently manually changing FileChangedCache.isInNodeModules method to return false for specified set of those dependencies.

This part of electron-forge also needs to be changed in order to precompile these dependencies: https://github.com/electron-userland/electron-forge/blob/master/src/util/compile-hook.js#L13

@paulcbetts do you think it would make sense to create an option for this? If so, I'm happy to work on a PR with this. Please also kindly give some pointers on what would be the best way to accomplish that so that such option could be also used with electron-prebuilt-compile

mhagmajer avatar Apr 29 '17 16:04 mhagmajer

@mhagmajer What reason do you have to ship precompiled source files? I'm trying to understand the scenario here

anaisbetts avatar Apr 29 '17 17:04 anaisbetts

@paulcbetts, thanks for taking time to reply!

There is a couple of reasons:

  • We have a few packages that encapsulate business logic, device protocols and text processing algorithms that we reuse across different JavaScript clients and our Node.js server. These packages are for internal consumption only and it's much more convenient for us to not have to compile them before release. Specifically, we believe that ES6 is first-class language for JavaScript environments and no compilation should be required. Also if you consider source maps and Flow type annotations, having to compile at the package level really affects the app development experience.
  • Compilation obfuscates the code preventing developers from being able to quickly test changes to code in node_modules with their app.
  • Async/await abstraction for handling asynchronous code with promises is implemented differently depending on environment: Regenerator, Fibers (that's what Meteor uses on the server side) or natively. We'd like to be able to choose what Babel plugins to use for async/await (if any) on application level (that's when know the target environment) rather than package level.
  • Packager for react-native which also aims at providing seamless development experience, like you guys do, allows for compiling dependencies as well.

We could use git modules for all this, but we prefer to do npm install directly from GitHub, since we already use npm for handling other dependencies. This would be an opt-in mechanism so there would be no performance impact for users who only depend on precompiled libraries.

mhagmajer avatar Apr 30 '17 11:04 mhagmajer

@paulcbetts my use case is, my project is so sensitive to the final bundle size that I have to enable tree shaking for building. So, sometimes I want to import source files of the depended modules directly like this: import vec2 from 'gl-matrix/src/gl-matrix/vec2'

leungwensen avatar Jul 27 '17 02:07 leungwensen