vue 配置babel

来源:互联网 发布:青海干部网络教育 编辑:程序博客网 时间:2024/06/01 18:21

首先install babel

cnpm install --save-dev babel-loader babel-core babel-preset-env babel-plugin-transform-runtime babel-plugin-istanbul babel-polyfill babel-preset-stage-2 babel-register


webpack module配置

module: {  rules: [    {      test: /\.vue$/,      loader: 'vue-loader',      options: {        loaders: {          scss: 'vue-style-loader!css-loader!sass-loader' // <style lang="scss">        }      }    },    {      test: /\.js$/,      exclude: /(node_modules|bower_components)/,      loader: 'babel-loader'    }  ]}

为了兼容ie 入口处加入 babel-polyfil

entry: {  app: ['babel-polyfill', './src/main.js']},

然后在根目录新建.babelrc文件 加入配置项

{  "presets": [    ["env", { "modules": false }],    "stage-2"  ],  "plugins": ["transform-runtime"],  "comments": false,  "env": {    "test": {      "presets": ["env", "stage-2"],      "plugins": [ "istanbul" ]    }  }}

原创粉丝点击