【问题标题】:Grunt change index.html referenceGrunt 更改 index.html 参考
【发布时间】:2016-10-12 00:13:04
【问题描述】:

使用 grunt 时,是否可以更改 html 文件中的引用。

例如,作为构建过程的一部分,我将文件名从 style.css 更改为 style.min.css。

我想做的是在我的 index.html 文件中更改对样式表的引用以使用缩小版本。

【问题讨论】:

    标签: build reference gruntjs


    【解决方案1】:

    是的,看看grunt-usemin。自述文件非常详尽。 :)

    https://github.com/yeoman/grunt-usemin

    【讨论】:

    【解决方案2】:

    避免在 html 标记中定义块 cmets 的另一种可能的解决方案是安装名为:grunt-text-replace的插件

    通过 npm 安装插件:

    $ npm install grunt-text-replace --save-dev

    然后将以下内容添加到您的Gruntfile

    Gruntfile.js:

    grunt.initConfig({
    
        pkg: grunt.file.readJSON('package.json'),
    
        /* UPDATES CSS SRC REFERENCED IN YOUR THE HTML FILE */
        replace: {
            cssLink: {
                src: ['./src/index.html'], //<--- The path to your html file
                overwrite: true,
                replacements: [{
                    // Subsitute src="css/ below with the path to your CSS file.
                    from: 'src="css/style.css',
                    // Subsitute src="css/ above with the path to your minified CSS file.
                    to: 'src="css/style.min.css'
                }]
            }
        }
    
    });
    
    grunt.loadNpmTasks('grunt-text-replace');
    
    grunt.registerTask('default', [
        'replace:cssLink'
    ]);
    

    };

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      相关资源
      最近更新 更多