Vue之webpack之Babel

现在想把es6的代码,转成es5的代码。

记录一下方法:

首先新建一个webpack_babel

然后执行

npm init -y

会自动生成一个package.json的文件

 安装babel插件:

npm install --save-dev babel-loader @babel/core @babel/plugin-transform-runtime @babel/runtime @babel/plugin-proposal-class-properties

安装babel预设

npm install @babel/preset-env --save-dev

增加配置文件:.babelrc

{
    "presets": ["@babel/preset-env"],
    "plugins": ["@babel/plugin-transform-runtime","@babel/plugin-proposal-class-properties"]
}

***************webpack的配置文件****************

npm install webpack webpack-cli --save-dev

新建一个webpack的配置文件

webpack.config.js

内容如下:

const path = require('path');
 
module.exports = {
    entry: './src/main.js',
    output:{
        path: path.resolve(__dirname,'dist'),
        filename :'bundle.js'
    },
    module:{
        rules:[
            { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
        ]
    }
 
}

在package.json里面添加如下内容

 

在main.js里面写一个es6的语法内容

console.log(111);
 
 
class Person{
    static info = {name:'sz',age:20}
}
 
console.log(Person.info)

执行命令

npm run build

结果OK

 

***********************************中间过程出现的错误解决如下:***************************************

 

出现如下错误:

官网解释如下:

https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets

 大概意思就是这个用不了了。我们去掉吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值