Skip to content
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

Support file extensions in Babel build #335

Merged
merged 3 commits into from Oct 27, 2020

Conversation

nrabinowitz
Copy link
Collaborator

At present, it isn't possible to specify a custom list of file extensions to build in babel.config.js - see babel/babel#8652. There's an open PR for this support in Babel, but at the moment the only way to convince the Babel CLI to parse files with extensions other than .js and .jsx is to provide the list on the command line.

This PR adds support for custom extensions via ocular build --extensions ".js,.ts", allowing the use of ocular-dev-tools for Typescript via @babel/preset-typescript.

@@ -5,6 +5,7 @@ set -e
DEV_TOOLS_DIR=`node -e "require('ocular-dev-tools/node/module-dir')()"`
CONFIG=`node $DEV_TOOLS_DIR/node/get-config.js ".babel.configPath"`
MODULES=`node $DEV_TOOLS_DIR/node/get-config.js ".modules" | sed -E "s/,/ /g"`
EXTENSIONS=".es6,.js,.es,.jsx,.mjs"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current @babel/cli default - it was easier to specify here than leave out.

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically handle things like this in ocular-dev-tools.js config file.

Regardless of how we do it, let's make sure we also update the docs.

In particular, I assume the babel defaults have to be repeated when overriding so maybe mention that in the docs and list them out?

I assume this is for adding typescript files - we could consider supporting those by default. i.e. the mere act of allowing typescript doesn't force repos to start using it...

@nrabinowitz
Copy link
Collaborator Author

We typically handle things like this in ocular-dev-tools.js config file.

Makes sense, I can move the settings there.

Regardless of how we do it, let's make sure we also update the docs.

Will do.

I assume this is for adding typescript files - we could consider supporting those by default. i.e. the mere act of allowing typescript doesn't force repos to start using it...

This is for TS via Babel, which seemed like the best option. I didn't add .ts to the list by default because then Babel tries to handle .d.ts files unless you explicitly ignore them, and fails. We could add this to the default Babel ignore setting, but it could still be a breaking change for any repo overriding ignore, so this seemed like the least intrusive option.

@ibgreen
Copy link
Collaborator

ibgreen commented Oct 27, 2020

We typically handle things like this in ocular-dev-tools.js config file.

Makes sense, I can move the settings there.

Regardless of how we do it, let's make sure we also update the docs.

Will do.

I assume this is for adding typescript files - we could consider supporting those by default. i.e. the mere act of allowing typescript doesn't force repos to start using it...

This is for TS via Babel, which seemed like the best option. I didn't add .ts to the list by default because then Babel tries to handle .d.ts files unless you explicitly ignore them, and fails. We could add this to the default Babel ignore setting, but it could still be a breaking change for any repo overriding ignore, so this seemed like the least intrusive option.

Understood. Seems reasonable as a first step.

Not clear why the .d.ts files should cause failures though. They are very valid TS syntax, big frameworks like THREE.js use this approach.

@ibgreen
Copy link
Collaborator

ibgreen commented Oct 27, 2020

I see, they are interpreted as .ts... how annoying, there must be a solution.

@ibgreen ibgreen merged commit e050e02 into uber-web:master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants