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');
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