Laravel Mix doesn't seem to transpile ES6 when importing packages
See original GitHub issue- Laravel Mix Version: 1.0.7
- Node Version: 8.1.3
- NPM Version: 5.1.0
- OS: macOS 10.12.6 Beta
Description:
Laravel Mix doesn’t seem to transpile ES6 when importing packages
Steps To Reproduce:
Installed laravel mix according to documentation for a standalone project.
created the standard directory structure (src/app.js
, src/app.scss
, created a folder dist
) and added a custom file as myPackage.js.
src/app.js
now contains the following:
import { initTabSwitcher } from './myPackage.js';
initTabSwitcher('.tabs a');
Running npm run dev
and npm run production
works fine now.
To the Problem
If i put myPackage.js
into my own git repository (as I want to share the functions across projects), install it via npm ("myPackage": "git+ssh://git@myServer.com:myUser/myPackage.git"
) and import it this way:
import { initTabSwitcher } from 'myPackage';
initTabSwitcher('.tabs a');
I get this error upon running npm run production
:
Unexpected token: name (matchesFn) [./~/myPackage/src/app.js:3,0][/app.js:97,6]
npm run dev
runs absolutely fine, but does not minify anything.
I also tried installing uglifyJS by adding "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony"
into my devDependencies. It didn’t change anything.
Is Laravel Mix not applying transpilation to imported modules? Am I doing something wrong or is this a bug?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:15 (1 by maintainers)
Top GitHub Comments
For anybody else who wants a work around as @domstubbs said you can change the exclusions
Currently this is a fully working
webpack.mix.js
example that may be useful for peopleThe default Babel rules exclude the node_modules directory.
I’ve posted a sample config override here which has sorted this for me. I’m still excluding node_modules in general, my only exception is the foundation-sites package, which currently requires transpiling.