Skip to content

Conversation

Hokid
Copy link
Contributor

@Hokid Hokid commented May 13, 2018

If we add a dependency to transpileDependencies list then it will not
been transpiled by babel. This PR make it possible.

Hokid added 2 commits May 13, 2018 19:58
If we add a dependency to `transpileDependencies` list then it will not been transpiled by babel. This PR make it possible.
@yyx990803
Copy link
Member

yyx990803 commented May 15, 2018

/cc @hzoo - what is the most idiomatic way in Babel 7 to force dependencies to be transpiled using the .babelrc or package.json of the project root?

'openBrowser',
'pluginResolution'
'pluginResolution',
'babelHelpers'
Copy link
Member

Choose a reason for hiding this comment

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

I don't see why this needs to be placed in cli-shared-utils. It's used only by cli-plugin-babel and should be placed in that package instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because cli-plugin-typescript also use babel-loader, may be in the future this will need there or some where else

const config = babelHelpers.loadUsersConfig(api.resolve('.'))

// prevent from ignore
config.ignore = [babelHelpers.resolveNodeModulesIgnorePattern(transpileDependencies)]
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed because we already have the exclude rule above which applies babel-loader only to the correct files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you are right

filename: 'package.json'
}

const partial = babel.loadPartialConfig(options)
Copy link
Member

Choose a reason for hiding this comment

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

why use loadPartialConfig then manually normalize instead of just using loadOptions?

Copy link
Contributor Author

@Hokid Hokid May 15, 2018

Choose a reason for hiding this comment

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

loadPartialConfig loads only users config(from: package.json, .babelrc, ...etc). both loadPartialConfig and loadOptions return not valid config for passing it to the babel-loader, this why there is need manually normilize config.


const options = {
cwd: rootDir,
filename: 'package.json'

Choose a reason for hiding this comment

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

Could someone clarify what specifically this is meant to do? Babel's configuration can vary per-file, so by doing this you're essentially loading the subset of the configuration that happens to apply to this specific filename.

I'd be happy to help make things work more easily with Babel, but at the moment this all seems to be going against a bunch of Babel's expectations.

const config = babelHelpers.loadUsersConfig(api.resolve('.'))

babelLoader
.options(config)

Choose a reason for hiding this comment

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

How does babelLoader here end up calling Babel exactly? I'd normally expect the loader to do all the work of reading the config, so I'm not totally following why this tries to read the config up front.

@Hokid
Copy link
Contributor Author

Hokid commented May 17, 2018

@loganfsmyth, @yyx990803
So many questions. There are suggestions how to do it better?

…al dependencies using nearest babel config in project's root for external dependencies
@yyx990803
Copy link
Member

@Hokid thanks a lot of the PR - after some discussion with the Babel team, the current solution is by always using babel.config.js which gives us the desired behavior (see 1279b3e).

@MartinPeverelli
Copy link

@yyx990803 @Hokid I'm sorry but I can't seem to understand how to make this work.
I have an SFC loaded via npm from a repository. Its main entry point is a wrapper.js that handles the import/export.
I understand that since the package is inside node_modules, the transpile process that takes place during npm run test:unit is ignoring it, and when my module under test tries to import it, it fails.

How can I use this transpileDependencies keys in order to force the npm run test:unit process to transpile a given package?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants