首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gulp在dist中创建src目录结构

gulp在dist中创建src目录结构
EN

Stack Overflow用户
提问于 2016-06-15 16:22:10
回答 1查看 349关注 0票数 5

我得到了以下gulp任务,

代码语言:javascript
复制
const gulp = require('gulp');
const del = require('del');
const typescript = require('gulp-typescript');
const tscConfig = require('./tsconfig.json');
const sourcemaps = require('gulp-sourcemaps');
const print = require('gulp-print');

// clean the contents of the distribution directory
gulp.task('clean', function () {
  return del('dist/**/*');
});

// TypeScript compile
gulp.task('compile', ['clean'], function () {
  return gulp
    .src(tscConfig.files)
    .pipe(print(function (filepath) {
      return 'Processing ' + filepath + '...';
    }))
    .pipe(sourcemaps.init())
    .pipe(typescript(tscConfig.compilerOptions))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist/app'));
});

gulp.task('build', ['compile']);
gulp.task('default', ['build']);

和一个目录结构

代码语言:javascript
复制
|
+- dist
|
+- src 
|   |
|   +- app
|   |   |
|   |   + - example.ts

现在,如果我运行gulp build,我会在dist中得到另一个app/src,即

代码语言:javascript
复制
|
+- dist
|   |
|   + - app
|        |
|        + - src 
|             |
|             + - app
|                  |
|                  + - example.js
|                  + - example.js.map
+- src 
|   |
|   +- app
|   |   |
|   |   + - example.ts   

这不是我想要的。我如何告诉gulp创建下面的目录结构呢?

代码语言:javascript
复制
|
+- dist
|   |
|   + - app
|        |
|        + - example.js
|        + - example.js.map 
|
+- src 
|   |
|   +- app
|   |   |
|   |   + - example.ts 

我需要gulp-replace来做这件事吗?还是有别的选择?

编辑:tsconfig.json如下:

代码语言:javascript
复制
{
    "compilerOptions": {
        "outDir": "dist/app",
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "suppressImplicitAnyIndexErrors": true
    },
    "files": [
        "src/app/**/*.ts"
    ]
}
EN

回答 1

Stack Overflow用户

发布于 2016-06-15 18:24:15

我求助于使用gulp-rename,如果有人能想到更好的解决方案,我渴望听到它。

代码语言:javascript
复制
gulp.task('compile', function () {
  return gulp
    .src(tscConfig.files)
    .pipe(print(function (filepath) {
      return 'Processing ' + filepath + '...';
    }))
    .pipe(sourcemaps.init())
    .pipe(typescript(tscConfig.compilerOptions))
    .pipe(rename(function (path) {
      if (path.dirname === 'src\\app') {
        path.dirname = '';
      } else {
        path.dirname = path.dirname.replace('src\\app\\', '');
      }
    }))
    .pipe(print(function (filepath) {
      return 'Generated file: ' + filepath;
    }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist/app'));
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37829873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档