构建 Yeoman 应用程序会破坏 CSS 背景图像

2024-04-04

我正在尝试将现有项目迁移到 Yeoman/Grunt/Bower。更改里面的路径后Gruntfile.js我注意到图像路径没有正确构建:

background:transparent url(/Users/lucian/Projects/[PROJECT]/src/main/resources/com/app/public/portal/.tmp/images/bg.header.png) center top no-repeat scroll;

彻底检查完所有内容后,我回到 Yeoman AngularJS 生成的项目并检查是否发生了同样的事情。所以我添加到main.css:

.marketing {
    background-image: url("../images/yeoman.png");
  margin: 40px 0;
}

在构建项目后,我注意到完全相同的事情:

background-image:url(/Users/lucian/Projects/yeomantest/.tmp/images/yeoman.png);

默认Gruntfile.js生成的 Yeoman 看起来像这样:

// Generated on 2014-05-07 using generator-angular 0.8.0
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {

  // Load grunt tasks automatically
  require('load-grunt-tasks')(grunt);

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    yeoman: {
      // configurable paths
      app: require('./bower.json').appPath || 'app',
      dist: 'dist'
    },

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower: {
        files: ['bower.json'],
        tasks: ['bowerInstall']
      },
      js: {
        files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
        tasks: ['newer:jshint:all'],
        options: {
          livereload: true
        }
      },
      jsTest: {
        files: ['test/spec/{,*/}*.js'],
        tasks: ['newer:jshint:test', 'karma']
      },
      styles: {
        files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
        tasks: ['newer:copy:styles', 'autoprefixer']
      },
      gruntfile: {
        files: ['Gruntfile.js']
      },
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [
          '<%= yeoman.app %>/{,*/}*.html',
          '.tmp/styles/{,*/}*.css',
          '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },

    // The actual grunt server settings
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
      },
      livereload: {
        options: {
          open: true,
          base: [
            '.tmp',
            '<%= yeoman.app %>'
          ]
        }
      },
      test: {
        options: {
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        }
      },
      dist: {
        options: {
          base: '<%= yeoman.dist %>'
        }
      }
    },

    // Make sure code styles are up to par and there are no obvious mistakes
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js'
      ],
      test: {
        options: {
          jshintrc: 'test/.jshintrc'
        },
        src: ['test/spec/{,*/}*.js']
      }
    },

    // Empties folders to start fresh
    clean: {
      dist: {
        files: [{
          dot: true,
          src: [
            '.tmp',
            '<%= yeoman.dist %>/*',
            '!<%= yeoman.dist %>/.git*'
          ]
        }]
      },
      server: '.tmp'
    },

    // Add vendor prefixed styles
    autoprefixer: {
      options: {
        browsers: ['last 1 version']
      },
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/styles/',
          src: '{,*/}*.css',
          dest: '.tmp/styles/'
        }]
      }
    },

    // Automatically inject Bower components into the app
    bowerInstall: {
      app: {
        src: ['<%= yeoman.app %>/index.html'],
        ignorePath: '<%= yeoman.app %>/'
      }
    },

    // Renames files for browser caching purposes
    rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/scripts/{,*/}*.js',
            '<%= yeoman.dist %>/styles/{,*/}*.css',
            '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= yeoman.dist %>/styles/fonts/*'
          ]
        }
      }
    },

    // Reads HTML for usemin blocks to enable smart builds that automatically
    // concat, minify and revision files. Creates configurations in memory so
    // additional tasks can operate on them
    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js: ['concat', 'uglifyjs'],
              css: ['cssmin']
            },
            post: {}
          }
        }
      }
    },

    // Performs rewrites based on rev and the useminPrepare configuration
    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
      options: {
        assetsDirs: ['<%= yeoman.dist %>']
      }
    },

    // The following *-min tasks produce minified files in the dist folder
    cssmin: {
      options: {
        root: '<%= yeoman.app %>'
      }
    },

    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,gif}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    svgmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.svg',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    htmlmin: {
      dist: {
        options: {
          collapseWhitespace: true,
          collapseBooleanAttributes: true,
          removeCommentsFromCDATA: true,
          removeOptionalTags: true
        },
        files: [{
          expand: true,
          cwd: '<%= yeoman.dist %>',
          src: ['*.html', 'views/{,*/}*.html'],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    // ngmin tries to make the code safe for minification automatically by
    // using the Angular long form for dependency injection. It doesn't work on
    // things like resolve or inject so those have to be done manually.
    ngmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/concat/scripts',
          src: '*.js',
          dest: '.tmp/concat/scripts'
        }]
      }
    },

    // Replace Google CDN references
    cdnify: {
      dist: {
        html: ['<%= yeoman.dist %>/*.html']
      }
    },

    // Copies remaining files to places other tasks can use
    copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '.htaccess',
            '*.html',
            'views/{,*/}*.html',
            'images/{,*/}*.{webp}',
            'fonts/*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: ['generated/*']
        }]
      },
      styles: {
        expand: true,
        cwd: '<%= yeoman.app %>/styles',
        dest: '.tmp/styles/',
        src: '{,*/}*.css'
      }
    },

    // Run some tasks in parallel to speed up the build process
    concurrent: {
      server: [
        'copy:styles'
      ],
      test: [
        'copy:styles'
      ],
      dist: [
        'copy:styles',
        'imagemin',
        'svgmin'
      ]
    },

    // By default, your `index.html`'s <!-- Usemin block --> will take care of
    // minification. These next options are pre-configured if you do not wish
    // to use the Usemin blocks.
    // cssmin: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/styles/main.css': [
    //         '.tmp/styles/{,*/}*.css',
    //         '<%= yeoman.app %>/styles/{,*/}*.css'
    //       ]
    //     }
    //   }
    // },
    // uglify: {
    //   dist: {
    //     files: {
    //       '<%= yeoman.dist %>/scripts/scripts.js': [
    //         '<%= yeoman.dist %>/scripts/scripts.js'
    //       ]
    //     }
    //   }
    // },
    // concat: {
    //   dist: {}
    // },

    // Test settings
    karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true
      }
    }
  });


  grunt.registerTask('serve', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'bowerInstall',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  });

  grunt.registerTask('server', function (target) {
    grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
    grunt.task.run(['serve:' + target]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'concurrent:test',
    'autoprefixer',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'bowerInstall',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngmin',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'rev',
    'usemin',
    'htmlmin'
  ]);

  grunt.registerTask('default', [
    'newer:jshint',
    'test',
    'build'
  ]);
};

关于可能出什么问题的任何线索吗?谢谢!


是什么修复了 CSSbackground-image对我来说,加速就是添加一个 CSS 模式options,它会查找 CSS 中的所有资源引用并将其替换为已更新的资源。

// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
  ...
  ...
  options: {
    ...
    ...
    // This is so we update image references in our ng-templates
    patterns: {
      js: [
        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
      ],
      css: [
        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the CSS to reference our revved images']
      ]
    }
  }
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

构建 Yeoman 应用程序会破坏 CSS 背景图像 的相关文章

随机推荐

  • 启动时加载 FastAPI 项目中的模型

    所以我目前正在开发一个为多种 NLP 服务提供服务的 FastAPI 项目 为此 我想提供来自 spacy 和 Huggingface 的不同模型 自从那些模型相当大的推理时间为每个发布请求加载模型相当长 我的想法是在 FastAPI 启动
  • 如何更改handleError?

    我有 jquery 脚本 它应该向我的文件发送响应 如果一切顺利 我会成功 但如果错误 我应该得到错误函数 但我得到jQuery handleError is not a function jQuery handleError s xml
  • 为 Python 3 安装 ipdb? [复制]

    这个问题在这里已经有答案了 我安装了ipdb https pypi python org pypi ipdb using pip 但我仍然得到 ImportError No module named ipdb 我还需要做其他事情才能引入这个
  • module.exports 返回未定义

    我目前是新来的Node JS 今天我试图read文件中的数据data json 这是 JSON 文件 username rahul v7 password 9673 username 7vik password 3248 username
  • phpmyadmin - Mysql 没有权限

    我在 Windows 7 上安装了 wamp 2 1 但是 当我打开 phpMyAdmin 时 出现错误 Mysql No Provileges 我卸载了wamp并重新安装了几次 但没有帮助 有谁知道如何解决这个问题 另外 当我尝试从 my
  • 使用 JavaScript 打开和关闭 CKEditor 4 内联编辑

    我需要能够使用按钮打开 关闭内联编辑 请参阅此处的内联编辑示例 http nightly v4 ckeditor com 3559 samples inlineall html http nightly v4 ckeditor com 35
  • 在 C 系列中,在循环中为什么“小于或等于”比“小于”符号更受青睐? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 为什么在 C 系列语言中 当我们对任何循环使用计数器时 最优选的比较是Greater Equal To lt 或者它的倒数 请看一下这三段代码
  • 使用 css 绘制图像内的曲线

    是否可能以及如何在图像顶部和底部内制作一条曲线 请参见图像 我怎样才能用CSS实现这一点 将您的图像设置为 div 上的背景图像并使用此技术 我在示例中使用了纯红色 这里我使用伪元素来创建顶部和底部的曲线 请注意 顶部和底部偏移量是每个伪元
  • Mockito:验证来自内部匿名类的方法调用

    我有一个正在测试的类 其中包含一个具有内部匿名类的方法 匿名类中的方法之一调用被测类中的方法 但 Mockito 似乎没有意识到这一点 public class ClassUnderTest Dependency dependency pu
  • C# 中的 SplitContainer 拆分器?

    i am using a split container For some reason the splitter looks like this 很难看到 就是两条黑线中间那条微弱的两条线 我该如何解决这个问题并在两条线之间添加填充 我使
  • Log4Net 可用于 adoappender 的数据库字段 - 似乎还有更多,即 method_name?

    我最近创建了简单的 log4net 数据库表 用于通过 adonet 附加程序进行日志记录 并且它有效 但后来我注意到另一个网站使用额外的字段 看 哇 我很想知道在哪里可以获得可用字段名称的列表 例如 Method name 真的让我思考
  • 使用相对导入路径时 Aurelia 捆绑失败

    我将 aurelia 与 typescript 一起使用 我想避免使用相对导入路径 例如 import DialogBox from resources elements dialog box 反而 import DialogBox fro
  • 具有unpivot自动抓取列列表(oracle 11g)

    这是一个后续问题将一行转置为多行 Oracle https stackoverflow com questions 2344403 transpose one row into many rows oracle 我希望能够反转任意查询结果
  • ubuntu 12.04 中 android-ndk-r9d-linux-x86 的 ndk-gdb 出现错误

    我在ubuntu 12 04中使用android ndk r9d linux x86的ndk gdb来调试android本机应用程序 hello jni 但它收到此错误 WARNING The shell running this scri
  • 无限滚动抓取网站

    我写了很多抓取工具 但我不太确定如何处理无限滚动条 如今 大多数网站 例如 Facebook Pinterest 都有无限滚动条 您可以使用 selenium 废弃 twitter 或 facebook 等无限滚动网站 步骤 1 使用 pi
  • 我可以将 xmodem 协议与 PySerial 一起使用吗?

    我通过 PySerial 与串行设备建立了工作连接 但我也想通过 xmodem 协议传输文件作为我的程序的一部分 哪一种是最平台中立的方式来做到这一点 最坏的情况 我可以close my serial SerialPython中的对象及其使
  • 如何在Python中从.pb文件恢复Tensorflow模型?

    我有一个 tensorflow pb 文件 我想将其加载到 python DNN 中 恢复图形并获取预测 我这样做是为了测试创建的 pb 文件是否可以做出与正常 Saver save 模型类似的预测 我的基本问题是 当我使用上述 pb 文件
  • Laravel Web 和 API 控制器结构。分开与干燥

    我想构建一个同时使用 Web 和 API 部分的 Laravel 应用程序 常见的 也是我的 问题是是否使用单独的控制器 有 2 个选项 独立控制器Laravel API 控制器结构 https stackoverflow com ques
  • CryptoStream 和经过身份验证的加密模式

    我有兴趣提供一个在 Net 中使用的托管 dll 它提供经过身份验证的加密服务 DLL 可以在 WPF 程序或 ASP 应用程序中使用 我有几个与 Microsoft 的加密和流模型相关的问题 经过身份验证的加密模式 CCM CWC EAX
  • 构建 Yeoman 应用程序会破坏 CSS 背景图像

    我正在尝试将现有项目迁移到 Yeoman Grunt Bower 更改里面的路径后Gruntfile js我注意到图像路径没有正确构建 background transparent url Users lucian Projects PRO