Grunt使用模板的usemin

7

假设有如下目录结构:

– Gruntfile.js
– app
    |– index.php
    |– js
    |– css
    |– templates
         |– template.php
– dist

我该如何配置grunt usemin以更新我的模板文件中与使用模板的index.php相对应的样式和脚本引用?

当前任务看起来像这样:

useminPrepare: {
    html: '<%= yeoman.app %>/templates/template.php',
    options: {
        dest: '<%= yeoman.dist %>'
    }
},
usemin: {
    html: ['<%= yeoman.dist %>/{,*/}*.php'],
    css: ['<%= yeoman.dist %>/css/*.css'],
    options: {
        dirs: ['<%= yeoman.dist %>']
    }
}

模板内部的块看起来像这样:

<!-- build:js js/main.js -->
    <script src="js/script1.js"></script>
    <script src="js/script2.js"></script>
<!-- endbuild -->
1个回答

4
好的,我找到了解决方法: 解决方案是使用备用搜索路径选项:
<!-- build:<type>(alternate search path) <path> -->
... HTML Markup, list of script / link tags.
<!-- endbuild -->

构建块现在看起来是这样的:
<!-- build:js(app) js/main.js -->
    <script src="js/script1.js"></script>
    <script src="js/script2.js"></script>
<!-- endbuild -->

而usemin任务的配置如下:
usemin: {
    html: '<%= yeoman.dist %>/templates/template.php',
    css: ['<%= yeoman.dist %>/css/*.css'],
    options: {
        dirs: ['<%= yeoman.dist %>']
    }
}

1
遗憾的是,在template.php中无法使用实际的php代码。 - gang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接