babel

【你应该了解的】抽象语法树AST

余生颓废 提交于 2020-04-14 17:44:14
【推荐阅读】微服务还能火多久?>>> 团队: skFeTeam  本文作者:李世伟 作为前端程序员,webpack,rollup,babel,eslint这些是不是经常用到?他们是打包工具,代码编译工具,语法检查工具。他们是如何实现的呢?本文介绍的抽象语法树,就是他们用到的技术,是不是应该了解一下呢? 本文没有晦涩难懂的理论,也没有大段大段的代码,完全从零开始,小白阅读也无任何障碍。通过本文的阅读,您将会了解AST的基本原理以及使用方法。 前言 什么是抽象语法树? AST(Abstract Syntax Tree)是源代码的抽象语法结构树状表现形式。下面这张图示意了一段JavaScript代码的抽象语法树的表现形式。 抽象语法树有什么用呢? IDE的错误提示、代码格式化、代码高亮、代码自动补全等 JSLint、JSHint、ESLint对代码错误或风格的检查等 webpack、rollup进行代码打包等 Babel 转换 ES6 到 ES5 语法 注入代码统计单元测试覆盖率 目录 1.AST解析器 2.AST in Babel 3.Demo with esprima 4.思考题 1.AST解析器 1.1 JS Parser解析器 AST是如何生成的? 能够将JavaScript源码转化为抽象语法树(AST)的工具叫做JS Parser解析器。 JS Parser的解析过程包括两部分

CSS and Images files not coming after transpiling package with babel in new CRA

我们两清 提交于 2020-04-13 06:10:42
问题 I am importing CSS as import './style.css'; and images in CSS with background URL property. What I want is to make a package, publish it to npm without building and then install it into a new CRA and use it there. Using self made npm package in react. Failed to compile. From here I got to know that to use that installed package now I have to transpile it. But the issue is my js/jsx are getting transpiled from ES6 to ES5 but the images and CSS aren't coming into the new transpiled folder.

How to enable optional chaining with Create React App and TypeScript

為{幸葍}努か 提交于 2020-04-12 09:59:23
问题 Support for the experimental syntax 'optionalChaining' isn't currently enabled I was getting the above error. I followed this post and added "@babel/plugin-proposal-optional-chaining": "^7.7.4" into my devDependencies . Then I am getting this error, Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation. So I followed this post and added .babelrc file into my project's root { "presets": ["react", "es2015",

How to enable optional chaining with Create React App and TypeScript

孤人 提交于 2020-04-12 09:58:12
问题 Support for the experimental syntax 'optionalChaining' isn't currently enabled I was getting the above error. I followed this post and added "@babel/plugin-proposal-optional-chaining": "^7.7.4" into my devDependencies . Then I am getting this error, Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation. So I followed this post and added .babelrc file into my project's root { "presets": ["react", "es2015",

vue-cli3.0之vue.config.js的配置项(注解)

天大地大妈咪最大 提交于 2020-04-11 20:01:43
module.exports = { // 部署应用时的基本 URL baseUrl: process.env.NODE_ENV === 'production' ? '192.168.60.110:8080' : '192.168.60.110:8080', // build时构建文件的目录 构建时传入 --no-clean 可关闭该行为 outputDir: 'dist', // build时放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录 assetsDir: '', // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径。 indexPath: 'index.html', // 默认在生成的静态资源文件名中包含hash以控制缓存 filenameHashing: true, // 构建多页面应用,页面的配置 pages: { index: { // page 的入口 entry: 'src/index/main.js', // 模板来源 template: 'public/index.html', // 在 dist/index.html 的输出 filename: 'index.html', // 当使用 title 选项时,template 中的 title

How to config webpack to transpile files from other lerna packages (ejected from create-react-app)

一笑奈何 提交于 2020-04-11 06:26:09
问题 I'm trying to build a lerna package with a create-react-app package and a simple component library. My component is as follows: import React, { Component } from "react"; import PropTypes from "prop-types"; class Layout extends Component { render = () => { let style = { fontSize: 14, fontFamily: "-apple-system, system-ui, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif", fontWeight: 400 };

How to config webpack to transpile files from other lerna packages (ejected from create-react-app)

此生再无相见时 提交于 2020-04-11 06:25:58
问题 I'm trying to build a lerna package with a create-react-app package and a simple component library. My component is as follows: import React, { Component } from "react"; import PropTypes from "prop-types"; class Layout extends Component { render = () => { let style = { fontSize: 14, fontFamily: "-apple-system, system-ui, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif", fontWeight: 400 };

how to exclude css files from eslint parser in React

孤人 提交于 2020-04-10 08:35:11
问题 I need to exclude css files from the eslint parser. Currently when I run eslint src/** this is checking all the files including css files. . Please find below my eslintrc file contents. module.exports = { "parser": "babel-eslint", "extends": "airbnb", "plugins": [ "react", "jsx-a11y", "import" ], "env" : { "browser": true } "rules": { "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], }, }; 回答1: .eslintignore file to ignore styles would work nicely. Inside, do something

how to exclude css files from eslint parser in React

跟風遠走 提交于 2020-04-10 08:35:08
问题 I need to exclude css files from the eslint parser. Currently when I run eslint src/** this is checking all the files including css files. . Please find below my eslintrc file contents. module.exports = { "parser": "babel-eslint", "extends": "airbnb", "plugins": [ "react", "jsx-a11y", "import" ], "env" : { "browser": true } "rules": { "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], }, }; 回答1: .eslintignore file to ignore styles would work nicely. Inside, do something

Transform JSX to JS using babel

♀尐吖头ヾ 提交于 2020-04-10 03:33:26
问题 I'm new to babel and I'm trying to convert my main.jsx file to main.js. I installed the following babel plugin. npm install --save-dev babel-plugin-transform-react-jsx Created a file called .babelrc in the application root directory. { "plugins": ["transform-react-jsx"] } My app is using the express server, so on running node app.js I was expecting the babel to transform main.jsx to main.js but nothing happens. Can any one point out what I'm doing wrong ? 回答1: if you are only using babel to