babeljs

Can you choose which ES6 features to transpile with Babel?

 ̄綄美尐妖づ 提交于 2020-01-03 13:36:50
问题 For example, is there an option to pass Babel to only transpile arrow functions, or let/const? My use case is to remove transpiling for certain features as browsers widely support them. 回答1: Yes, you can pass a whitelist option to specify specific transformations to run, or a blacklist to specific transformations to disable. They are listed here: http://babeljs.io/docs/advanced/transformers/. See also: http://babeljs.io/docs/usage/options/ Update: The answer above applies to Babel 5. In Babel

Why does “transform-es2015-modules-commonjs” add “use strict” in Babel 6?

眉间皱痕 提交于 2020-01-02 03:59:45
问题 Using Babel 6, I'm trying not to have "use strict" in my compiled code. I've found that it's the "transform-es2015-modules-commonjs" plugin (in "es2015" preset) which is what adds it. In the source-code it seems to inherit "babel-plugin-transform-strict-mode" , which if I remove it, it still works fine, i.e. it compiles the import "…" into require(…) without adding the "use strict". So why does "transform-es2015-modules-commonjs" force strict mode? 回答1: In the ES6 specification, there are two

Async/Await not waiting

廉价感情. 提交于 2020-01-02 02:23:06
问题 I'm running into an issue which I don't fully understand. I feel like there are likely concepts which I haven't grasped, code that could be optimized, and possibly a bug thrown in for good measure. To greatly simplify the overall flow: A request is made to an external API The returned JSON object is parsed and scanned for link references If any link references are found, additional requests are made to populate/replace link references with real JSON data Once all link references have been

How do I create a main import file in ES6?

三世轮回 提交于 2020-01-02 02:11:06
问题 I am looking to create a main import file using ES6 syntax. I have a components directory with an index.js file. I would like to export the imports if that makes sense. Essentially, I would like to import then export the individual component files into the index file so I can de-structure my imports from any other files like so: import {Comp1, Comp2} from "./components" How do I do this with ES6 syntax? 回答1: You can do: export * from "./components" // or export {Comp1, Comp2} from ".

Gulp TypeError: Path must be a string. Received undefined

[亡魂溺海] 提交于 2020-01-01 16:07:12
问题 I want to run build command but got the error message: TypeError: Path must be a string. Received undefined. Do you guys have any ideas? Thanks. gulp.task('build', function () { browserify("./src/components/source.js") .transform("babelify", {presets: ["es2015", "react"]}) .bundle() .pipe(gulp.dest(path.resolve(__dirname, './src/app.js'))); }); Below is the tracestack details: TypeError: Path must be a string. Received undefined at assertPath (path.js:8:11) at Object.posix.resolve (path.js

Gulp TypeError: Path must be a string. Received undefined

≡放荡痞女 提交于 2020-01-01 16:06:53
问题 I want to run build command but got the error message: TypeError: Path must be a string. Received undefined. Do you guys have any ideas? Thanks. gulp.task('build', function () { browserify("./src/components/source.js") .transform("babelify", {presets: ["es2015", "react"]}) .bundle() .pipe(gulp.dest(path.resolve(__dirname, './src/app.js'))); }); Below is the tracestack details: TypeError: Path must be a string. Received undefined at assertPath (path.js:8:11) at Object.posix.resolve (path.js

Compile .jsx files instead of .js using babel

痞子三分冷 提交于 2020-01-01 15:32:39
问题 I'm starting to learn ReactJs , and I was trying to build an environment from scratch using this "builder". Everything works pretty well, but I'd like to work with .jsx files instead of .js (the text editor screws up otherwise, and ir feels better using a different extension for not-compiled scripts) However, I didn't manage to compile such .jsx files, it only works with .js files. This is the configuration files for .babelrc : { "presets":["es2015","react"] } And my webpack.config.js : var

Compile .jsx files instead of .js using babel

无人久伴 提交于 2020-01-01 15:32:15
问题 I'm starting to learn ReactJs , and I was trying to build an environment from scratch using this "builder". Everything works pretty well, but I'd like to work with .jsx files instead of .js (the text editor screws up otherwise, and ir feels better using a different extension for not-compiled scripts) However, I didn't manage to compile such .jsx files, it only works with .js files. This is the configuration files for .babelrc : { "presets":["es2015","react"] } And my webpack.config.js : var

SCRIPT1002: Syntax error in IE11 with React + Babel + Webpack

徘徊边缘 提交于 2020-01-01 12:31:51
问题 I'm trying to get my React App with ES2015 functionalities running in IE >= 11 using Webpack + Babel. The setup is custom, using the inferno-compat layer, so no create-react-app used here. However - despite applying the latest babel-polyfill and babel-preset-env practices to my .babelrc and webpack config, I still get a SCRIPT1002: Syntax error within my bundle.js when trying to access the app with IE11. When I follow the syntax error reference in IEs console, this is the part within the

.babelrc ignore field seems to be ignored

淺唱寂寞╮ 提交于 2020-01-01 04:07:10
问题 I've got a .babelrc file at the root of a project: { "presets": ["es2015"], "ignore": [ "src" ] } When I compile it with babel src --out-dir dist , the src folder is still compiled onto the dist folder. However, when I launch the command babel src --out-dir dist --ignore src , nothing is compiled. Why is the ignore property of my .babelrc being ignored? By the way, I've tried with some subfolder or files, and the same issue occurs. 回答1: This was an issue with babel-cli. It has been fixed in