Answer the question
In order to leave comments, you need to log in
How to add ES 2020 to Vue 2?
How to add new babel preset in vue 2?
No matter how he asked Google, this question he cannot understand.
I want to use the new ES features, especially the "?" operator, when diving deep into objects.
Answer the question
In order to leave comments, you need to log in
A sketch of a slightly less hacky way than the one suggested above:
const { transformSync } = require("@babel/core");
const fs = require('fs');
const babelTransform = {
transformCode: (_, code) => transformSync(`(function(){${code}}())`, {
filename: "",
ast: false,
retainLines: true,
babelrc: true,
compact: true,
minified: true
}).code.replace(/;$/,'')
};
const addBabelTransform = (options) => {
const { compilerOptions } = options;
const modules = compilerOptions && compilerOptions.modules ? compilerOptions.modules.concat(babelTransform) : [babelTransform];
return {
...options,
compilerOptions: {
...compilerOptions,
modules
}
}
}
module.exports = {
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.tap(addBabelTransform);
},
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question