-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Support source field in package.json to enable babel on symlinked modules #1101
Conversation
nice writeup & very interesting idea. This would be super useful for dev productivity. Would you use babel by default? How does parcel know which babel plugins need to be applied for the module? When using lerna, I usually will have all my scripts at the project top level and things like .babelrc is not even present in the module. |
|
I like this idea, and I would be happy to make Meteor respect the Clarifying question: who decides what Babel configuration is used to compile the package, if it uses the
I'm having trouble imagining why a package author would not want to provide a If there's really no reason for a package author not to provide the field, then it might be better just to compile all linked npm packages, instead of requiring a special field, because there's a cost to getting package authors to adopt a new convention. I'm also a little skeptical that the To ask the same question from a different angle: what's the benefit to the package author of opting into the As a package author, I might prefer to let my more ambitious users figure out compilation for themselves, rather than making promises I can't keep about use cases I can't anticipate.
I think this is common enough and important enough to consider, especially because compiled With Meteor's approach, since the linked package is viewed as part of the application, you can ignore arbitrary files or directories by putting them in a Meteor also supports creating symbolic links to packages that are installed within |
Thanks for all the feedback. I'll try to address the questions below.
We respect the
Yep, we'd watch the source files for changes rather than the dist files.
As described above, the linked package describes its own build configuration, not the application. Applications shouldn't need to know how to build other node_modules.
By default, node_modules are considered precompiled. The I'd expect many linked packages in an application to actually be owned by the same author as the app itself. This is definitely the case in a monorepo, and probably common in other cases as well. If a linked package doesn't have a |
We're discussing something similar for the create-react-app build system in facebook/create-react-app#4092. In that proposal, the consumer specifies which packages are source packages and builds those packages according to the consumer's (CRA's) build spec -- it doesn't honor the source package's .babelrc. This would conflict with this parcel approach because the package could contain a "source" entry point that contains to JSX/etc., but the package itself doesn't have the .babelrc to transpile it. A couple ideas to make them compatible: (1) default to use the consumer's build if the source package doesn't have .babelrc, or (2) in addition to what is already proposed, support the same "sourcePackages" config that facebook/create-react-app#4092 proposes which would explicitly list which packages should be built according to the consumer's build spec. Another related question with the current approach: Is there a way for thesource package's build to honor the consumer's desired target environment? E.g., for the consumer to provide babel-preset-env settings? It doesn't seem like a huge issue, but kind of annoying if you're using something as source, but not to be able to build it to the desired target spec. This is one nice feature of delegating the entire build to the consumer as proposed in facebook/create-react-app#4092. |
Got here from #948 Not a symlink'd module.
|
As for your question about babel-preset-env settings, Parcel already uses the |
I'm afraid that we introduced new property under |
The |
@devongovett is |
Oh, this only works when you're linking. Not when it's published. I see. |
* Update description of node_modules handling Updates the Transforms page to be consistent with parcel-bundler/parcel#559 and parcel-bundler/parcel#1101. * Improve wording Configuration files outside of node_modules will never ever apply to things inside of node_modules
@devongovett WDYT about publishing packages with a |
Related issues: #13, #948
Summary
When developing several modules locally, it is useful to symlink them into your project with
npm link
or similar. This is also common with monorepos managed by yarn workspaces and lerna. If those linked modules need to be compiled with babel, it is annoying to have to run a manual build step after each change since Parcel does not run babel on node_modules by default.This PR adds support for a new
source
field to package.json. When a module with asource
field is symlinked, we enable babel compilation on that module. If the module is not symlinked but installed normally, babel compilation is disabled as usual. This is a development only feature, and should not be relied on for production use.The
source
field also operates as an alias so you can change the resolution of files within a module when it is being used as source code. For example, it is common to pre-compile thesrc
folder of a module tolib
or something prior to publishing to npm. Themain
field in package.json, would then point to e.g.lib/index.js
. When developing locally, you would want this to point to source code instead of compiled code. Thesource
field lets you do this.Examples
Treat all files as source code, don't change the resolution
When compiling from source, use bar.js as the entry point
When compiling from source, alias specific files
When compiling from source, alias using glob patterns
The last example allows you to e.g. replace your entire
lib
directory withsrc
soimport 'my-module/lib/test.js
would resolve tomy-module/src/test.js
. You could also use a top-level catch-all pattern like"**": "./src/$1"
for packages like lodash that have many files in the root to replace e.g.lodash/cloneDeep
withlodash/src/cloneDeep
.Questions
source
field, or is symlinking enough to enable babel? I think it will be pretty common to need a source field anyway for aliasing (i.e. the first example will be uncommon), so maybe not a big deal to require one.import "my-module/dist/index.js"
. Currently, babel would still be applied as there is no way to know which files are source files and which are compiled. Again, I don't think this should be very common but curious to hear opinions.Feedback
I think this feature will be very useful for local development. Please let me know your feedback!
cc. @tj @CentaurWarchief @Vanuan @gaearon