webpack-babel转码器
作者:互联网
webpack文件
- index.js
console.log("aaaa");
console.log("bbbb");
var a = 111;
var b = 2222;
import "./index.css"
require("./main.less")
require("./other.scss")
// es6的箭头函数
let fn = () => (console.log("es6的箭头函数"))
fn();
// es7 类的注解
@log
class Test{
constructor() {
console.log("test is a constructor");
}
}
let t = new Test()
function log(target) {
console.log("target",target,"log fun");
}
npx webpack 打包发现并不支持ES7类的注解
下载babel转码器
babel官网:https://babeljs.io/docs/en/babel-plugin-proposal-decorators
yarn add -D babel-loader @babel/core @babel/preset-env @babel/plugin-proposal-decorators
rules: {
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
"@babel/preset-env"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties"]
]
}
}
},
}
npx webpack 打包发现浏览器支持ES7类的注解
标签:console,log,plugin,babel,webpack,码器,proposal 来源: https://blog.csdn.net/lxs19930928/article/details/121890219