Tag: gulp ecmascript 6

我可以使用Node运行在ES6中编写的Gulp任务吗?

我通过Babel在Node上使用ES6。 我可以使用run-babel脚本运行ES6脚本。 所以,这将工作: node run-babel build.js //build.js is written in ES6 但是现在我想从Gulp任务中访问这些ES6脚本中的一个,但是Gulp运行在vanilla节点上。 有没有办法在ES6中编写Gulp任务?

为什么用Webpack和Gulp这么大(> 1.9Mb)构build输出包?

我通过node / npm使用webpack和webpack来构build和uglify浏览器应用程序。 问题是输出app.js大约是1.9Mb。 这似乎太大,并build议我可能错过了一些东西。 我使用gulp build –release开始构build过程 这是我的大嘴文件: import path from 'path'; import cp from 'child_process'; import gulp from 'gulp'; import gulpLoadPlugins from 'gulp-load-plugins'; import del from 'del'; import mkdirp from 'mkdirp'; import runSequence from 'run-sequence'; import webpack from 'webpack'; import minimist from 'minimist'; const $ = gulpLoadPlugins(); const argv = minimist(process.argv.slice(2)); const src […]

Gulp和Babel:错误:找不到模块

我有一个项目,我已经build立了使用大gulp和babel 。 一切工作正常,除了当我创build一个模块,并导入它从ES6转换到ES6它不起作用。 我收到一个错误: Error: Cannot find module 'hello.js' at Function.Module._resolveFilename (module.js:440:15) at Function.Module._load (module.js:388:25) at Module.require (module.js:468:17) 这是我的gulpfile.babel.js : import gulp from "gulp"; import babel from "gulp-babel" import concat from "gulp-concat" const dirs = { src: "src", dest: "build" } gulp.task("build", () => { return gulp.src(dirs.src + "/**/*.js") .pipe(babel()) .pipe(concat("build.js")) .pipe(gulp.dest(dirs.dest)) }); gulp.task("default", ["build"]); […]

节点asynchronous脚本有时会意外结束

我有一个节点脚本调用很多进程打包文件。 大多数情况下,这种方法很好,但是偶尔也可能(每5次电话中平均有1次),它只停在中间,总是在同一个地方。 具体而言,失败时的日志结尾如下所示: Finished task 1! Compiling jsajax.js… Compiling apps.js… 我没有得到任何错误或任何东西,所以我不知道甚至看什么。 这里的设置是我的主文件(index.js)使用co和生成器来调用所需的asynchronous进程,并产生结果。 其中的一部分是吞噬,这是发生这个问题的地方。 我在这里包含了调用代码和gulp任务,因为剩下的代码太长,无法显示所有内容。 如果您认为需要的话,我很高兴收录更多。 谢谢! 调用函数: const createJS = function* createJS () { try { yield gulpFile.createJS(); return 0; } catch(err) { console.error(err); return CONSTANTS.ERROR; } }; 吞噬任务: const createJS = function () { const buildProps = PropertiesReader('build.properties'), distLoc = buildProps.get('distLoc'), installLoc = buildProps.get('installLoc'), […]

使用Gulp with Babel错误导入

我想用babel来编译我已经用一个简单的文件(routes / users.js)尝试的ES6代码,如下所示 import express from 'express'; var router = express.Router(); /* GET users listing. */ router.get('/', (req, res, next) => { res.send('respond with a resource'); }); export default router; 我已经添加到吞咽文件以下 gulp.task('esconverter', () => { return gulp.src('routes/users.js') .pipe(babel({ presets: ['es2015'] })) .pipe(gulp.dest('dist')); }); 我已经将任务添加到默认 gulp.task('default', ['esconverter' ,'nodemon'], () => { console.log("Done"); }); 当我运行它(gulp.js)时,我得到了以下错误 /Users/i0/Webs/blog10/bl/routes/users.js:1 (function […]

如何在es2015中导入rethinkdbdash

我是在node.js中编程的新手。 我已经安装了gulp-babel ,它把我的js文件放在/ src里,并把经过转换的源文件移动到/ dist文件夹(这个工作真棒)。 我想使用rethinkdbdash而不是rethinkdb 。 在es5中,我们将执行以下操作: var r = require('rethinkdbdash')(); 在es6中,使用导入的正确方法是什么? import 'rethinkdbdash'; var r = rethinkdbdash(); 谢谢您的帮助。 我希望答案也能帮助有同样问题的人。

'… paths.js'是什么意思在'gulp.src(,{base:'。'})'?

我有以下吞咽任务: // Compile ES6 to ES5 and copy to dist gulp.task('babel', () => gulp.src([…paths.js, '!gulpfile.babel.js'], { base: '.' }) .pipe(plugins.newer('dist')) .pipe(plugins.sourcemaps.init()) .pipe(plugins.babel()) .pipe(plugins.sourcemaps.write('.', { includeContent: false, sourceRoot(file) { return path.relative(file.path, __dirname); } })) .pipe(gulp.dest('dist')) ); 根据Gulp Doc( gulp.src ),我了解到gulp.src会发出匹配提供的glob或者globs数组的文件。 但是我无法理解这里'… paths.js'的含义。 项目目录中没有以“paths.js”命名的文件。 有没有人能帮我理解呢?

和谐旗帜如何运行?

使用–harmony标志可以在node.js中实现同样的效果: node –harmony app.js 所以它会join对EcmaScript6的支持。 如何用和谐旗运行gulp命令?

可以在es6中写一个大文件吗?

问题:如何在ES6中编写我的gulp文件,这样我就可以使用import来代替require并在function()使用=>语法? 我可以使用io.js或节点的任何版本。 gulpfile.js: import gulp from "./node_modules/gulp/index.js"; gulp.task('hello-world', =>{ console.log('hello world'); }); 错误: import gulp from "./node_modules/gulp/index.js"; ^^^^^^ SyntaxError: Unexpected reserved word gulp.task('hello-world', =>{ ^^ SyntaxError: Unexpected token => 在node_modules/gulp/bin/gulp.js我把第一行改成了#!/usr/bin/env node –harmony