javascript - Webpack fails to build ES6 in external packages -
i'm trying use es6 npm package (in case 1 called gamesystem) in project , build webpack (and babel) fails build es6 code inside external dependency, why that? if have same code dependency relative path works fine.
app code:
'use strict'; import world 'gamesystem'; // breaks //import world '../node_modules/gamesystem'; // breaks //import world '../gamesystem'; // works (copied same directory gamesystem outside node_modules directory) let world = new world(); error:
error in ./~/gamesystem/world.js module parse failed: /home/user/project/node_modules/gamesystem/world.js line 3: unexpected token may need appropriate loader handle file type. | 'use strict'; | | import system './system'; | | export default class world { @ ./src/app.js 3:18-39 webpack config:
'use strict'; // modules let webpacknotifierplugin = require('webpack-notifier'); let htmlwebpackplugin = require('html-webpack-plugin'); let config = { entry: { app: __dirname + '/../src/app.js' }, devtool: 'source-map', devserver: { stats: { modules: false, cached: false, colors: true, chunk: false }, proxy: require('./devproxy') }, module: { loaders: [{ test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: { presets: ['es2015', 'stage-0'] } }, { test: /\.css$/, loader: 'style!css' }, { test: /\.html$/, loader: 'raw' }] }, plugins: [ new webpacknotifierplugin(), new htmlwebpackplugin({ template: __dirname + '/../src/index.html', inject: 'body', minify: false }) ] }; module.exports = config;
you're explicitly excluding node_modules babel-loader:
exclude: /node_modules/, you'll need tweak if want pass modules node_modules through babel. might consider explicit includes this:
// sure req path // var path = require('path') include: [ // include app path path.resolve(__dirname, 'my-app-js-path'), // include gamesystem modules /\bgamesystem\b/, ],
Comments
Post a Comment