gpt4 book ai didi

javascript - Grunt,将 html 文件复制到构建时的脚本文件夹

转载 作者:可可西里 更新时间:2023-11-01 02:45:32 25 4
gpt4 key购买 nike

我在 yeoman 中使用 Angular 生成器。在 gruntfile.js 中,/app/views 中的每个 html 文件都被复制到 dist/views。但我喜欢将我的指令模板保存在与指令本身相同的文件夹中。

例子:

/app/scripts/widgets/mywidget.directive.js
/app/scripts/widgets/mywidget.tmpl.html

当我构建项目时,我希望 html 文件最终位于与上面相同的文件夹结构中。

这可能应该在 gruntfile.js 的复制部分完成。

copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'*.html',
'images/{,*/}*.{webp}',
'styles/fonts/{,*/}*.*'
]
}...

我试图将它添加到 src 数组中:

    '<%= yeoman.dist %>/scripts/{,*/}*.tmpl.html'

没用。有什么想法吗?

最佳答案

您可以使用对 gruntfile 的代码修改将所有 .tmpl.html 从 app/scripts/* 移动到 dist/scripts/* ,如下所示。

files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'*.html',
'views/{,*/}*.html'
]
}, {
// This block handles copying the .tmpl.html from app/scripts to dist/scripts
expand: true,
cwd: '<%= yeoman.app %>/scripts',
dest: '<%= yeoman.dist %>/scripts',
src: '{,*/}*.tmpl.html'
}
...

您还需要将新目录添加到 usemin block 中,以确保 filerev 更新使其进入您的模板

usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html',
'<%= yeoman.dist %>/scripts/{,*/}*.html'],
...

您可能还想将目录添加到 htmlmin 以缩小为 html

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

已更新这些脚本现在反射(reflect)了将任何 .tmpl.html 从 app/scripts/*/ 移动到 dist/scripts/*/。如果您的文件夹结构在脚本内部不止一层,请将 {,*/}*.html 更改为 **/*.html

关于javascript - Grunt,将 html 文件复制到构建时的脚本文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34178850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com