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);
},
}