babeljs

Javascript 6to5 (now Babel) export module usage

帅比萌擦擦* 提交于 2019-12-30 01:03:26
问题 I'm still a beginner, i try to to export and import one class into a main file, the other class in the others class file and use them. And then gulp ES5 code with 6to5 (now Babel). // file a.js import B from 'b.js'; class A { constructor() { B.methodB(); } } export default A; // file b.js class B { methodB() { console.log('hi from b'); } } export default B; // file main.js import A from 'a.js'; new A(); My gulpfile: var gulp = require('gulp'); var to5 = require('gulp-6to5'); gulp.task(

Javascript 6to5 (now Babel) export module usage

点点圈 提交于 2019-12-30 01:03:09
问题 I'm still a beginner, i try to to export and import one class into a main file, the other class in the others class file and use them. And then gulp ES5 code with 6to5 (now Babel). // file a.js import B from 'b.js'; class A { constructor() { B.methodB(); } } export default A; // file b.js class B { methodB() { console.log('hi from b'); } } export default B; // file main.js import A from 'a.js'; new A(); My gulpfile: var gulp = require('gulp'); var to5 = require('gulp-6to5'); gulp.task(

UglifyJS throws unexpected token: keyword (const) with node_modules

北城余情 提交于 2019-12-30 00:42:34
问题 A small project I started make use a node module (installed via npm ) that declares const variables. Running and testing this project is well, but browserify fails when UglifyJS is executed. Unexpected token: keyword (const) Here is a generic Gulp file that I have successfully been using for a few other past projects without this issue (i.e. without that particular node module). gulpfile.js 'use strict'; const browserify = require('browserify'); const gulp = require('gulp'); const source =

React syntax error when adding class properties

喜欢而已 提交于 2019-12-29 09:10:34
问题 I'm writing a react app with babel and webpack. It's been going along well until I tried to add a property on a class - specifically trying to use a Dropdown from React-Toolbox (http://react-toolbox.com/#/components/dropdown) and for the time being before getting data connected, I directly copied this: class DropdownTest extends React.Component { state = { value: 'ES-es', }; handleChange = (value) => { this.setState({value: value}); }; render () {} Here is my very-slightly-modified version:

Transpiling Array.prototype.flat away with @babel?

空扰寡人 提交于 2019-12-29 07:38:28
问题 I inadvertently introduced a backwards compatibility issue in my React app by using Array.prototype.flat . I was very surprised this didn't get resolved by transpiling - I thought this would result in es2015 compatible code. How can I get Babel 7 to transpile this? (If my reading of the sources is right in Babel 6 there was still a plugin for this but since this has begun to roll out to browsers support has been dropped?) Tools: @babel/core@7.0.0 webpack@4.18.0 My top-level configuration

import and call a function with es6 [duplicate]

此生再无相见时 提交于 2019-12-29 06:35:22
问题 This question already has answers here : Pass options to ES6 module imports (7 answers) Closed 4 years ago . Previously: var debug = require('debug')('http') , http = require('http') , name = 'My App'; With es6, how can I import and invoke right away like the first line? import debug from 'debug'(); is a no no? 回答1: You'll need two lines: import debugModule from 'debug'; const debug = debugModule('http'); The import syntax is a declarative import syntax, it does not execute any functions. 回答2

'import' and 'export' may only appear at the top level

。_饼干妹妹 提交于 2019-12-29 04:27:30
问题 I'm using webpack with vuejs. Webpack does its thing, but when I look at the outputted app.js file, it gives me this error. 'import' and 'export' may only appear at the top level I'm assuming it's a problem with babel not converting the code? Because I'm getting this in the browser when viewing the application. Unexpected token import Here's my entry.js for my vuejs application: /*jshint esversion: 6 */ import Vue from 'vue'; import App from './App.vue'; import VueRouter from 'vue-router';

Webpack with babel-loader not recognizing import keyword

丶灬走出姿态 提交于 2019-12-29 04:12:08
问题 I have this webpack.config.js : module.exports = { entry: './src/admin/client/index.jsx', output: { filename: './src/admin/client/static/js/app.js' }, loaders: [ { test: /\.jsx?$/, loader: 'babel', exclude: /node_modules/, query: { optional: ['runtime'] } } ], resolve: { extensions: ['', '.js', '.jsx'] } }; ...yet I still get this error: $ webpack -v Hash: 2a9a40224beb025cb433 Version: webpack 1.10.5 Time: 44ms [0] ./src/admin/client/index.jsx 0 bytes [built] [failed] ERROR in ./src/admin

Importing node modules from root directory using es6 and babel-node

淺唱寂寞╮ 提交于 2019-12-29 03:33:25
问题 I'm writing a node app with es6 using babel transpiler. I have 2 files index.js & my-module.js on my root directory - index.js - my-module.js my-module.js export let myFunc = () => { console.log('myFunc was called!!!'); } index.js import {myFunc} from './my-module'; myFunc(); if I run the following line from the command line everything works as expected. $ babel-node index.js >> myFunc was called!!! but if I remove the dot when importing my-module: import {myFunc} from '/my-module'; myFunc();

Debugging with webpack, ES6 and Babel

爷,独闯天下 提交于 2019-12-29 02:33:10
问题 This seems like something that should have been relatively simple to achieve, but alas. I have ES6 class: 'use strict'; export class BaseModel { constructor(options) { console.log(options); } }; and root module that uses it: 'use strict'; import {BaseModel} from './base/model.js'; export let init = function init() { console.log('In Bundle'); new BaseModel({a: 30}); }; My target is: pass the above through Babel, to get ES5 code pack the modules with webpack be able to debug the result After