【问题标题】:configure grunt to prevent minifying inline scripts配置 grunt 以防止缩小内联脚本
【发布时间】:2015-07-06 15:34:33
【问题描述】:

如何配置 grunt 和/或 usemin 步骤,使其不会触及正文内的内联脚本?

假设如下:

<html>
    <body>
        <script id="an-example" type="text/x-jsrender">
            <b>{{:data}}</b>
        </script>
    </body>
</html>

当我在本地运行grunt serve 时,一切正常,但是当我将它与grunt 打包时,我在index.html 中找不到脚本。

这是我的 Gruntfile.js 的一部分:

usemin: {
      options: {
        assetsDirs: [
          '<%= config.dist %>',
          '<%= config.dist %>/images',
          '<%= config.dist %>/styles'
        ]
      },
      html: ['<%= config.dist %>/{,*/}*.html'],
      css: ['<%= config.dist %>/styles/{,*/}*.css']
    },

【问题讨论】:

    标签: javascript gruntjs grunt-usemin


    【解决方案1】:

    实际上,脚本部分包含在以下 cmets 中:

    <!-- build:js({app,.tmp}) scripts/main.js -->
    ...
    <!-- endbuild -->
    

    这指示 Grunt 压缩/缩小/丑化同一 main.js 文件中的代码。

    将部分移到任何构建注释之外解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 2021-06-06
      • 2013-05-21
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多