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

[WIP] Add support for transpile packages installed via NPM #749

Closed
wants to merge 8 commits into from

Conversation

arunoda
Copy link
Contributor

@arunoda arunoda commented Jan 12, 2017

Fixes #706

Instructions

Add a field called transpileModules with an array of regexp patterns like this:

module.exports = {
 transpileModules : [
    /react-button/
  ]
}

Here Next.js checks every imported module with above patterns and transpile them if matched. By default it uses next/babel preset, but you can use a .babelrc file to customize it as you want.

In the above example, Next.js will transpile any module inside the node_modules directory which has "react-button" in it's pathname.

Note: Currently, Next.js only supports modules installed into node_modules. So, transpiling modules installed with npm link <my-comp-name> doesn't work well.

presets: [require.resolve('./build/babel/preset')],
extensions: ['.js'],
only: this.config.transpileModules || []
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Umm, babel-register is not for production. I'm not sure if it's acceptable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about that too. Need to read the source to dig more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I think we can go some kind of pre-compilation system.
For now, we can use this to test the functionality.

Choose a reason for hiding this comment

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

https://github.com/standard-things/esm looks promising. Maybe we could use this in production and babel-register in dev mode?

@arunoda arunoda changed the title Add support for transpile installed via NPM [WIP] Add support for transpile installed via NPM Jan 12, 2017
@rauchg rauchg added this to the 2.1 milestone Jan 12, 2017

In the above example, Next.js will transpile any module inside the `node_modules` directory which has "react-button" in it's pathname.

> Note: Currently, Next.js only supports modules installed into `node_modules`. So, transpiling modules installed with `npm link <my-comp-name>` doesn't work well.
Copy link

Choose a reason for hiding this comment

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

so it does not work with symlinks (like Lerna do?) not sure to understand that comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now yes it is.

@arunoda arunoda changed the title [WIP] Add support for transpile installed via NPM [WIP] Add support for transpile packges installed via NPM Jan 21, 2017
@arunoda arunoda changed the title [WIP] Add support for transpile packges installed via NPM [WIP] Add support for transpile packages installed via NPM Jan 21, 2017
@abstracthat
Copy link

Where are we at with this feature? I just ran into this problem and would be lovely to not have to add transpiled code to the component repo.

@ajoslin
Copy link

ajoslin commented Mar 3, 2017

I need this to work with symlink support (my project makes heavy use of Lerna).

I'd love to help contribute to get symlink support up and running. What steps need to be taken?

@traa
Copy link

traa commented Apr 14, 2017

Any possible workarounds to use Next.js with Lerna?

@timneutkens
Copy link
Member

@arunoda do we still want to take this?

@arunoda
Copy link
Contributor Author

arunoda commented May 28, 2017

Let's keep this open. I want to work on this someday.

@esteban-uo
Copy link

esteban-uo commented Jun 6, 2017

any status update on this issue @arunoda ? thx!

@timneutkens timneutkens removed this from the 2.1 milestone Jun 26, 2017

if (pattern.test(str)) return false
}

return /node_modules/.test(str)

Choose a reason for hiding this comment

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

would be cool if this was more generic to support monorepo scenarios. I'm happy to lend a hand to this feature if needed

@thealjey
Copy link

will this ever get merged?

@mattfelten
Copy link

What happened here? Looks like the feature died?

@rickbyington
Copy link

Yes, would really like my Lerna packages to be able to get transpiled.

@philcockfield
Copy link

philcockfield commented Nov 26, 2017

@timneutkens when you closed this, was it merged? Should the original example @arunoda gave work?

module.exports = {
transpileModules : [
    /react-button/
  ]
}

@timneutkens
Copy link
Member

@philcockfield no, check #3319

@philcockfield
Copy link

Thanks @timneutkens

@lock lock bot locked as resolved and limited conversation to collaborators May 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet