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

Add support for node_modules to be included in babel #860

Closed
wants to merge 1 commit into from

Conversation

adambutler
Copy link

@adambutler adambutler commented Sep 25, 2017

I've found dependencies that are ES6 fail during UglifyJs due to not first being handled by babel:

For example, my code has:

import { Foundation } from 'foundation-sites/js/foundation.core';
import { Reveal } from 'foundation-sites/js/foundation.reveal';
import { Tabs } from 'foundation-sites/js/foundation.tabs'

When I run:

$ rm -Rf public/packs
$ NODE_ENV=production RAILS_ENV=production rails webpacker:compile --trace

I get the following error:

ERROR in application-37763722852138e61493.js from UglifyJs
Unexpected character '`' [./node_modules/foundation-sites/js/foundation.util.core.js:24,0][application-37763722852138e61493.js:11323,124]

ERROR in Modals-8541f74f3cf2b70f4a0f.js from UglifyJs
Unexpected token: name (matchMedia) [./node_modules/foundation-sites/js/foundation.util.mediaQuery.js:21,0][Modals-8541f74f3cf2b70f4a0f.js:102,4]

ERROR in TabbedExamples-b873f916d365855bfd5d.js from UglifyJs
Unexpected character '`' [./node_modules/foundation-sites/js/foundation.util.core.js:24,0][TabbedExamples-b873f916d365855bfd5d.js:100,124]

This change adds the ability to include node_modules to be compiled by babel. It defaults to the current behaviour, which I'm not entirely sure is correct anyway.

Related: #395
Possibly related: #746

Copying in @dhh @gauravtiwari who have both touched package/loaders/babel.js.

@gauravtiwari
Copy link
Member

gauravtiwari commented Sep 25, 2017

@adambutler Thanks for this but if you want to include node_modules in your app, you can update the loader yourself in your environment.js

// config/webpack/environment.js
const { environment } = require('@rails/webpacker')

// Update an option directly
const babelLoader = environment.loaders.get('babel')
babelLoader.exclude = []

module.exports = environment

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.

2 participants