babel

ES6核心特性

江枫思渺然 提交于 2019-12-03 17:38:04
前言 ES6 虽提供了许多新特性,但我们实际工作中用到频率较高并不多,根据二八法则,我们应该用百分之八十的精力和时间,好好专研这百分之二十核心特性,将会收到事半功倍的奇效!写文章不容易,请大家多多支持与关注! 本文首发地址 GitHub博客 一、开发环境配置 这部分着重介绍: babel 编译ES6语法,如何用webpack实现模块化。 1.babel 为啥需要babel? ES6 提供了许多新特性,但并不是所有的浏览器都能够完美支持。下图是各个浏览器对ES6兼容性一览表(以export为例) 由上图可知,有些浏览器对于ES6并不是很友好,针对 ES6 的兼容性问题,很多团队为此开发出了多种语法解析转换工具(比如babel,jsx,traceur 等),可以把我们写的 ES6 语法转换成 ES5,相当于在 ES6 和浏览器之间做了一个翻译官。其中 Babel 是一个广泛使用的转码器,可以将ES6代码转为ES5代码,从而在现有环境执行。 如何配置babel? ·首先要先安装node.js,运行npm init,然后会生成package.json文件 ·npm install --save-dev babel-core babel-preset-es2015 babel-preset-latest ·创建并配置.babelrc文件//存放在项目的根目录下,与node_modules同级

Extracting Javascript gettext messages using Babel CLI extractor

旧时模样 提交于 2019-12-03 16:01:27
It is stated here that Babel can extract gettext messages for Python and Javascript files. Babel comes with a few builtin extractors: python (which extracts messages from Python source files), javascript, and ignore (which extracts nothing). The command line extractor is documented here - but with no examples on usage. Also in the same pointer above, there is some mention of a config file to be used with extraction, but not much expanded on. When I run the basic command for the extractor on a dir with js files, I get only the .PO header generated but no messages. $ pybabel extract /path/to/js

Flask-Babel localized strings within js

主宰稳场 提交于 2019-12-03 15:59:23
I'm pretty new to both Python and Flask (with Jinja2 as template engine) and I am not sure I am doing it the right way. I am using Flask-Babel extension to add i18n support to my web application. I want to get localized strings from my js code, for instance: var helloWorld = gettext('Hello, world'); console.log(helloWorld); //should log a localized hello world message For this, I configured babel (babel.cfg): [python: **/**.py] [jinja2: **/**.html] extensions=jinja2.ext.autoescape,jinja2.ext.with_ [javascript: **/**.js] encoding = utf-8 And its initialization is (imports omitted for simplicity

Babel: compile translation files when calling setup.py install

我们两清 提交于 2019-12-03 14:35:00
I'm developing a Flask application using Babel. Thanks to Distutils/Setuptools Integration , all the parameters of compile/extract/... functions are stored in setup.cfg and compiling the i18n files is as easy as ./setup.py compile_catalog Great. Now I would like this to be done automatically when running ./setup.py install In make 's words, that would be letting install target depend on compile_catalog target. The context We store only translation ( .po ) files in the code repository. .gitignore excludes .mo and .pot files from being tracked. When a developer pulls a new revision of the code,

gulp压缩js转义es6的常见错误及解决方案

99封情书 提交于 2019-12-03 13:37:33
"babel-cli": "^6.26.0", "babel-core": "^6.26.3", "babel-preset-es2015": "^6.24.1", "gulp-babel": "6", 如上代码所示,安装以上版本的babel插件,bable更新很快,当版本不一致会冲突,导致出现 Plugin/Preset files are not allowed to export objects, only functions 。 gulp压缩js代码如下 const uglify = require('gulp-uglify'); //js压缩 const babel = require("gulp-babel"); // gulp打包manager\page\dist\js gulp.task('revJs', ()=> { return gulp.src([filePath + '/page/dist/js/*.js']) .pipe(babel({//编译ES6 presets: ['es2015'] })) .pipe(uglify())//压缩js .pipe(gulp.dest( 'dist/manager/page/dist/js')) }) 来源: https://www.cnblogs.com/uimeigui/p/11797452.html

Why does React require Babel and Webpack to work?

好久不见. 提交于 2019-12-03 11:39:55
问题 I was looking at the wiki page of vue.js and saw this: When compared to React development, Vue can be integrated to an existing web application much more easily. Normally, a web application can start using Vue immediately by simply including the Vue.js JavaScript library. Usage with Webpack or Browserify, are not strictly necessarily. This is in stark contrast to React development where Usage with Webpack and Babel is unavoidable, therefore making converting existing web application much more

Difference between Webpack/Babel and react-scripts

你离开我真会死。 提交于 2019-12-03 10:29:36
问题 Recently i started working on web pack and react-scripts and i would like to know the advantages and disadvantages using them and how they are different from each other. 回答1: Basically speaking, they serve different purposes and usually show up together. I will explain what they are designed to do. babel Babel is a transpiler. It can translate all kinds of high version ECMAScript ( not only ECMAScript, but it's easy to understand) into ES5, which is more widely supported by browsers

对abel 转译 class 过程的研究----------------------引用

笑着哭i 提交于 2019-12-03 10:17:18
作为当下最流行的 JavaScript 编译器,Babel 替我们转译 ECMAScript 语法,而我们不用再担心如何进行向后兼容。 零、前言 虽然在 JavaScript 中对象无处不在,但这门语言并不使用经典的基于类的继承方式,而是依赖原型,至少在 ES6 之前是这样的。当时,假设我们要定义一个可以设置 id 与坐标的类,我们会这样写: // Shape 类function Shape(id, x, y) { this.id = id; this.setLocation(x, y);} // 设置坐标的原型方法Shape.prototype.setLocation = function(x, y) { this.x = x; this.y = y;}; 上面是类定义,下面是用于设置坐标的原型方法。从 ECMAScript 2015 开始,语法糖 class 被引入,开发者可以通过 class 关键字来定义类。我们可以直接定义类、在类中写静态方法或继承类等。上例便可改写为: class Shape { constructor(id, x, y) { // 构造函数语法糖 this.id = id; this.setLocation(x, y); } setLocation(x, y) { // 原型方法 this.x = x; this.y = y; }} 一个更符合“传统语言

Babel 7 - ReferenceError: regeneratorRuntime is not defined

喜夏-厌秋 提交于 2019-12-03 09:51:15
I have an application that is a node backend and a react frontend. I get the following error when i try to build/run my node application. Node: v10.13.0 Error: dist/index.js:314 regeneratorRuntime.mark(function _callee(productId) { ^ ReferenceError: regeneratorRuntime is not defined .babelrc { "presets": [ [ "@babel/preset-env", { "targets": { "node": "current" }, } ], "@babel/preset-react"], "plugins": [ "@babel/plugin-proposal-class-properties" ] } webpack.config.js { mode: "development", entry: "./src/index.js", target: "node", externals: [nodeExternals()], // in order to ignore all modules

How to debug NodeJS(ES6) code in VSCode editor?

馋奶兔 提交于 2019-12-03 09:30:34
问题 I am trying to debug my nodejs application written in ES6 from VSCode. But it is throwing following error: node --debug-brk=18712 --nolazy index.js Debugger listening on [::]:18712 /Users/rsiva/Projects/Siva/ntask/ntask-api/index.js:1 (function (exports, require, module, __filename, __dirname) { import express from "express"; ^^^^^^ SyntaxError: Unexpected token import at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js