gulp useref在根文件夹中构建文件

时间:2014-04-04 20:47:08

标签: gulp

我在项目中使用了yeoman的gulp webapp生成器,出于某些特殊原因,我需要在根文件夹中而不是在" dist"中生成文件。文件夹,但我的路径有些问题,下面是我的代码。

在HTML中:

<!-- build:js ../scripts/vendor/modernizr.js -->
<script src="bower_components/modernizr/modernizr.js"></script>
<!-- endbuild -->

在gulpfile.js

// HTML
gulp.task('html', function () {
    return gulp.src('app/*.html')
      .pipe($.useref())
      .pipe(gulp.dest('')) // I removed 'dist' here
      .pipe($.size());
});

它确实在根文件夹中生成了一个脚本文件夹和index.html,但index.html中的脚本路径是错误的。

<script src="../scripts/vendor/modernizr.js"></script>

我在gulpfile.js中找不到任何提及,我错过了什么吗?

3 个答案:

答案 0 :(得分:2)

试用gulp-replace-path插件

你可以试试这样的事情

.pipe($.replacePath('../', '')
.pipe(gulp.dest(dest));

答案 1 :(得分:1)

不幸的是,我认为您需要手动更改src脚本标记中的index.html属性,因为我认为如果没有正确的外观,它会动态地为您执行此操作。

无论如何,这是一个简单的改变。只需进入index.html并从../属性中删除src

希望有所帮助。

答案 2 :(得分:0)

对于咕噜声,我做过类似的事情。

replace: {
            prod: {
                src: ['../prod/**/css/*.css'],
                overwrite: true,
                replacements: [{
                    from: "../../../inc/",
                    to: "../../../../inc/"**
        }]
    }
}
相关问题