Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp 构建工具 #12

Open
magicdawn opened this issue Dec 4, 2014 · 5 comments
Open

gulp 构建工具 #12

magicdawn opened this issue Dec 4, 2014 · 5 comments

Comments

@magicdawn
Copy link
Owner

gulp through2.obj(transform_function_here)

想要接受到一串文件,实现concat类似操作
用 through https://github.com/dominictarr/through/blob/master/index.js
例子 https://github.com/wearefractal/gulp-concat/blob/master/index.js

@magicdawn
Copy link
Owner Author

gulp 的 路径 问题 https://github.com/wearefractal/vinyl

vinyl 有 base cwd relative
然后

gulp.src("src/**/*.js")
    pipe(gulp.dest("dist"))

那么文件就是
base是 src , 有path ,计算得到 relative,然后dest操作就是修改base,与relative得到新的path
所以 src/idnex.js -> dist/index.js

自己new gutil.File 的时候,提供 base,path就行了

@magicdawn
Copy link
Owner Author

gobble 构建工具

转换ES6 JS代码 https://github.com/gobblejs/gobble-es6-transpiler

gobble( 'src/js' ).transform( 'es6-transpiler' )

@magicdawn
Copy link
Owner Author

gulp deps

gulp.task('build', ['test1', 'test2'], function(){
  process.env.NODE_ENV = 'production';
});

const bluebird = require('bluebird');
gulp.task('test1', function(){
  return bluebird.delay(1000);
});

gulp.task('test2', function(){
  return bluebird.delay(2000);
});

结果

[11:29:12] Starting 'test1'...
[11:29:12] Starting 'test2'...
[11:29:13] Finished 'test1' after 1 s
[11:29:14] Finished 'test2' after 2 s
[11:29:14] Starting 'build'...
[11:29:14] Finished 'build' after 45 μs

gulp start

gulp.task('build', function(){
  gulp.start('test1', 'test2');
});


const bluebird = require('bluebird');
gulp.task('test1', function(){
  return bluebird.delay(1000);
});

gulp.task('test2', function(){
  return bluebird.delay(2000);
});

结果

[11:32:32] Starting 'build'...
[11:32:32] Starting 'test1'...
[11:32:32] Starting 'test2'...
[11:32:32] Finished 'build' after 2.8 ms
[11:32:33] Finished 'test1' after 1 s
[11:32:34] Finished 'test2' after 2 s

gulp.start Async

gulp.task('build', function(done){
  gulp.start('test1', 'test2', done);
});


const bluebird = require('bluebird');
gulp.task('test1', function(){
  return bluebird.delay(1000);
});

gulp.task('test2', function(){
  return bluebird.delay(2000);
});

结果

[11:34:47] Starting 'build'...
[11:34:47] Starting 'test1'...
[11:34:47] Starting 'test2'...
[11:34:48] Finished 'test1' after 1 s
[11:34:49] Finished 'test2' after 2 s

@magicdawn
Copy link
Owner Author

ts

import gulp from 'gulp'
import execa from 'execa'

interface TaskMeta {
  name?: string
  desc?: string
  flags?: Object
  run: () => Promise<void> | void
}
function taskFn(data: TaskMeta) {
  const run = data.run
  Object.assign(run, {
    description: data.desc,
    flags: data.flags,
    displayName: data.name,
  })
  return run
}
const task = (meta: TaskMeta) => gulp.task(taskFn(meta))

task({
  name: 'pkg',
  desc: '生成 pkg',
  async run() {
    execa.commandSync('pkg -t node12-mac .', {
      cwd: __dirname,
      stdio: 'inherit',
    })
  },
})

@magicdawn
Copy link
Owner Author

gulp v4 transitive deprecated deps

WARN  deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 WARN  deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 WARN  deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
 WARN  deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
 WARN  deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
 WARN  deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated

没怎么维护了, issue 直接视为 spam 关了
image

gulpjs/gulp#2641
gulpjs/gulp#2500

我们不解决问题, 解决提出问题的人~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant