前端开发
904
babel 问题
babel是负责转换ES 新版本语法到老版本js上的。
比如解构语法 ...
程序有如下报错
Syntax Error: Unexpected token 8 | let data_ = []; 9 | data.forEach(d => { > 10 | let d_ = {...d}; | ^ 11 | //产品名称 12 | if(d_.hasOwnProperty('productNo')){ 13 | d_.productName = product.getProductNameByProductNo(d_.productNo);
解决方法
yarn add -D babel-plugin-syntax-jsx yarn add -D babel-plugin-transform-runtime yarn add -D babel-plugin-transform-vue-jsx yarn add -D babel-preset-env yarn add -D babel-preset-stage-2
前端工程根目录建立.babelrc,写入如下内容
{ "presets": [ ["env", { "modules": false, "targets": { "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] } }], "stage-2" ], "plugins": [ "transform-runtime", "transform-vue-jsx" ] }
postcss的问题

Module build failed: Error: No PostCSS Config found in: E:\CODE\xxxxxx
新建.postcssrc.js文件,写入如下内容
module.exports = { "plugins": { "postcss-import": {}, "postcss-url": {}, // to edit target browsers: use "browserslist" field in package.json "autoprefixer": {} } }