使用webpack配置babel

429 阅读1分钟

{  "name": "mypro", 
 "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.42.0",
    "webpack-cli": "^3.3.11",
    "@babel/core": "^7.4.5",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/plugin-transform-runtime": "^7.4.4",
    "@babel/preset-env": "^7.4.5",
    "@babel/runtime": "^7.4.5",    
    "babel-loader": "^8.0.6"  
}}

这是package.json的代码核心代码:

    "@babel/core": "^7.4.5",  
    "@babel/plugin-proposal-class-properties": "^7.4.4",   
    "@babel/plugin-transform-runtime": "^7.4.4",
    "@babel/preset-env": "^7.4.5",
    "@babel/runtime": "^7.4.5",
    "babel-loader": "^8.0.6"

相信不少同学看的是老版的babel引用方式


添加.babelrc


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