Laravel mix transpile dependency

社会主义新天地 提交于 2019-12-08 03:55:01

问题


I'm trying to use the vuex-module-decorators library in a laravel mix project (using typescript). But I keep getting the error Uncaught TypeError: Class constructor VuexModule cannot be invoked without 'new'. This seems to be a known issue and can be resolved by adding transpileDependencies: ['vuex-module-decorators'] to my vue.config.js file which will tell babel to transpile the package.

Since I'm using laravel mix, adding a vue.config.js file doesn't do anything. And I can't figure out how to tell laravel mix to transpile the vuex-module-decorators dependency.

I tried adding { test: /\.js$/, loaders: ['babel-loader'] }, to the webpack config in webpack.mix.js (also with explicitly including the dependency) but it doesn't work.

So how can I tell laravel mix to transpile the vuex-module-decorators dependency (to es5)?

If it helps, here's my webpack.mix.js file:

mix
  .ts('resources/ts/app.ts', 'public/js')
  .stylus('resources/stylus/app.styl', 'public/css');

回答1:


I was able to point babel-loader at all .js files and that worked:

// In webpack.mix.js
mix.webpackConfig({
   module: {
     rules: [{
       test: /\.js?$/,
       use: [{
         loader: 'babel-loader',
         options: mix.config.babel()
       }]
     }]
   }
 });

However your compile times will be reduced if use a more specific test to target only the modules you need to transpile:

    test: /node_modules\/(vuex-module-decorators|vuex-persist)\/.+\.js$/,


来源:https://stackoverflow.com/questions/53344641/laravel-mix-transpile-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!