简体   繁体   English

gulp字体任务不将roboto-fontface文件添加到dist文件夹中

[英]gulp font task do not add roboto-fontface files into dist folder

I am using gulp serve:dist to build the angular project but when index page render it gives 404 error for all roboto fonts. 我正在使用gulp serve:dist来构建角度项目,但是当索引页呈现时,它会为所有roboto字体提供404错误。 see 看到 404错误

Search many SO questions and on github but none of them is working so far. 在github上搜索许多SO问题 ,但到目前为止都没有工作。 Here are my folder structure and code 这是我的文件夹结构和代码

/app/ /应用/

|-- bower_components
|-- bower.json
|-- dist
|-- gulp
|-- gulpfile.js
|-- karma.conf.js
|-- node_modules
|-- package.json
|-- README.md
|-- src

/bower_components/roboto-fontface/ / bower_components /的Roboto-fontface /

.
|-- bower.json ( content of this file is written below )
|-- css
|   |-- mixins.less
|   |-- mixins.scss
|   |-- roboto
|   |   |-- less
|   |   |   |-- roboto-fontface-black-italic.less
|   |   |   |-- ....  ....
|   |   |   `-- roboto-fontface-thin.less
|   |   |-- roboto-fontface.css
|   |   `-- sass
|   |       |-- roboto-fontface-black-italic.scss
|   |       |-- .... ....
|   |       `-- roboto-fontface-thin.scss
|   `-- roboto-condensed
|       |-- less
|       |   |-- roboto-condensed-fontface-bold-italic.less
|       |   |-- .... ....
|       |   `-- roboto-condensed-fontface-regular.less
|       |-- roboto-condensed-fontface.css
|       `-- sass
|           |-- roboto-condensed-fontface-bold-italic.scss
|           |-- .... ....
|           `-- roboto-condensed-fontface.scss
|-- fonts
|   |-- roboto
|   |   |-- Roboto-Black{/.eot,/.svg,/.ttf,/.woff,/.woff2}
|   |   |-- Roboto-Regular{/.eot,/.svg,/.ttf,/.woff,/.woff2}
|   |   `-- Roboto-Thin{/.eot,/.svg,/.ttf,/.woff,/.woff2}
|   `-- roboto-condensed
|       |-- Roboto-Condensed-Bold{/.eot,/.svg,/.ttf,/.woff,/.woff2}
|       `-- Roboto-Condensed-Regular{/.eot,/.svg,/.ttf,/.woff,/.woff2}

/bower_components/roboto-fontface/bower.json /bower_components/roboto-fontface/bower.json

{
    "name": "roboto-fontface",
    "description": "A simple package providing the Roboto fontface.",
    "version": "0.5.0",
    "main": [
        "./css/roboto/roboto-fontface.css",
        "./css/roboto-condensed/roboto-condensed-fontface.css",
        "./fonts/roboto/*.*",
        "./fonts/roboto-condensed/*.*"
    ],
    "ignore": [
        "**/.*",
        "node_modules",
        "bower_components",
        "test",
        "tests"
    ]
}

here is complete gulp/build.js and relevant font task is 这是完整的gulp / build.js ,相关的字体任务是

gulp.task('fonts', function () {
  return gulp.src($.mainBowerFiles())
    .pipe($.filter('**/*.{otf,eot,svg,ttf,woff,woff2}'))
    .pipe($.flatten())
    .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));
});

trial 1 试用1

gulp.task('copyfonts', function() {
   return gulp.src('../bower_components/roboto-fontface/fonts/**/*.{eot,svg,ttf,woff,woff2}')
   .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/fonts/')));
});

and

gulp.task('build', ['html', 'fonts', 'copyfonts', 'other']);

this does not work 这不起作用

trial 2 试用2

gulp.task('fonts:dev', function () {
    return gulp.src($.mainBowerFiles())
      .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}'))
      .pipe($.flatten())
      .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/fonts/')));
});

but this will add font-awesome and glyphicon .{eot,svg,ttf,woff,woff2} files into serve/fonts/ which are already in dist/fonts folder 但这会将font-awesome和glyphicon添加。{eot,svg,ttf,woff,woff2}文件放入dist / fonts文件夹中的serve / fonts /中

trial 3 试用3

added in main app/bower.json 添加在主app / bower.json中

"roboto-fontface": {
      "main": [
        "css/roboto-condensed/less/roboto-condensed-fontface.less"
      ]
    },

but still not working 但仍然无法正常工作


UPDATE (working) 更新(工作)

// copy Roboto fonts into Roboto Directory
gulp.task('copyfonts', function() {
  return gulp.src($.mainBowerFiles().concat('bower_components/roboto-fontface/fonts/roboto/*'))
    .pipe($.filter('{Roboto-Black,Roboto-Bold,Roboto-Medium,Roboto-Regular}.{eot,svg,ttf,woff,woff2}'))
    .pipe($.flatten())
    .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/Roboto')));
});

Above is working fine but here I need to copy fronts into /fonts/Roboto folder? 上面的工作正常,但是在这里我需要将前端复制到/ fonts / Roboto文件夹中?

If I do not add Roboto folder in gulp.dest than 404 error comes as it is looking fonts in fonts/Roboto folder? 如果我未在gulp.dest添加Roboto文件夹,则gulp.dest 404错误,因为它正在fonts / Roboto文件夹中查找字体?

where to change this fonts/Roboto folder name to to default /fonts folder? 在哪里将此字体/ Roboto文件夹名称更改为默认的/ fonts文件夹?

Here how I did to achieve this. 在这里,我如何做到这一点。 first update the version to roboto-fontface 0.7.0 and apply below steps 首先将版本更新为roboto-fontface 0.7.0并应用以下步骤

  1. added in /app/bower.json 添加在/app/bower.json中

     "overrides": { "roboto-fontface": { "main": [ "css/roboto/less/roboto-fontface.less" ] } } 
  2. in app/index.less app / index.less中

     @import "../../bower_components/roboto-fontface/css/roboto/less/roboto-fontface.less"; @roboto-font-path: "../../bower_components/roboto-fontface/fonts"; 
  3. add below line in html task here 在此处在html任务中添加以下行

     .pipe($.replace('../../bower_components/roboto-fontface/fonts/', '../fonts/')) .pipe($.replace('../../bower_components/fontawesome/fonts/', '../fonts/')) 
  4. add a new gulp task copyfonts which will copy Roboto fonts into Roboto Directory 添加一个新的gulp任务copyfonts ,它将把Roboto字体复制到Roboto目录中

     gulp.task('copyfonts', function() { return gulp.src($.mainBowerFiles().concat('bower_components/roboto-fontface/fonts/Roboto/*')) .pipe($.filter('{Roboto-Thin,Roboto-Medium,Roboto-Bold,Roboto-Regular}.{eot,svg,ttf,woff,woff2}')) .pipe($.flatten()) .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/Roboto/'))); }); 
  5. add these task in below order 按以下顺序添加这些任务

     gulp.task('war', ['html', 'fonts', 'copyfonts', 'other'], function () { 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM