通过 grunt 安装的 bower 不会将所有文件复制到 targetDir
bower install via grunt does not copy all files to targetDir
在继承的 Polymer 1.0 项目中,设置涉及一个 gruntfile,除其他外,它调用 bower 来安装必要的资源。但是在后面的步骤中,有些文件找不到,导致grunt任务失败。我对 bower 和 grunt 都是新手,感觉有点迷茫。
找不到的问题文件是myproject\components\polymer\polymer-mini.html
,虽然我通过手动复制文件找到了更多类似的位置。
我的第一步是隔离 bower 安装任务并在它运行时观察它。这是它在 gruntfile.js
:
中的配置
bower: {
install: {
options: {
targetDir: './components',
layout: 'byType',
install: true,
verbose: false,
cleanTargetDir: true,
cleanBowerDir: true,
bowerOptions: {}
}
}
}
通过在详细模式下执行单个步骤后暂停执行,我发现在安装过程中发生了以下情况:
- 旧
myproject/components
文件夹如果存在则删除
- 文件在
myproject/bower_components
文件夹中正常创建
- 然后文件被复制到 targetDir
myproject/components
- 然而,并非所有 文件似乎都到达那里
myproject/bower_components
复制后删除
比较 myproject/bower_components
和 myproject/components
的内容表明,原始文件夹中存在的许多文件在目标文件夹中丢失。例如,提到的 myproject/components/polymer
只包含一个 polymer.html
- 但是 myproject/bower_components/polymer
中有七个文件,包括缺少的 polymer-mini.html
。
显然,有些东西会过滤复制到 targetDir 的内容和不复制的内容。
我能以任何方式影响它吗?或者这个设置是否像现在这样正确?我已经看到 但不能充分利用它 - 除了接受的解决方案显然在安装 bower_components
之后手动复制所有内容。当然,一定有更好的方法吧?
我最终通过调用这样配置的 copy
任务独立于 Bower 任务复制文件:
copy: {
main: {
files: [
{ expand: true, cwd: 'bower_components/', src: ['**'], dest: 'components/', filter: 'isFile' }, // bower components
]
}
}
当然,在这种情况下,必须重新配置 bower 任务,不要删除要从中复制的 bower 目录。
bower: {
install: {
options: {
targetDir: './components',
layout: 'byType',
install: true,
verbose: false,
cleanTargetDir: true,
cleanBowerDir: false,
bowerOptions: {}
}
}
}
这不是我真正希望的,但与此同时它完成了工作。
在继承的 Polymer 1.0 项目中,设置涉及一个 gruntfile,除其他外,它调用 bower 来安装必要的资源。但是在后面的步骤中,有些文件找不到,导致grunt任务失败。我对 bower 和 grunt 都是新手,感觉有点迷茫。
找不到的问题文件是myproject\components\polymer\polymer-mini.html
,虽然我通过手动复制文件找到了更多类似的位置。
我的第一步是隔离 bower 安装任务并在它运行时观察它。这是它在 gruntfile.js
:
bower: {
install: {
options: {
targetDir: './components',
layout: 'byType',
install: true,
verbose: false,
cleanTargetDir: true,
cleanBowerDir: true,
bowerOptions: {}
}
}
}
通过在详细模式下执行单个步骤后暂停执行,我发现在安装过程中发生了以下情况:
- 旧
myproject/components
文件夹如果存在则删除 - 文件在
myproject/bower_components
文件夹中正常创建 - 然后文件被复制到 targetDir
myproject/components
- 然而,并非所有 文件似乎都到达那里
myproject/bower_components
复制后删除
比较 myproject/bower_components
和 myproject/components
的内容表明,原始文件夹中存在的许多文件在目标文件夹中丢失。例如,提到的 myproject/components/polymer
只包含一个 polymer.html
- 但是 myproject/bower_components/polymer
中有七个文件,包括缺少的 polymer-mini.html
。
显然,有些东西会过滤复制到 targetDir 的内容和不复制的内容。
我能以任何方式影响它吗?或者这个设置是否像现在这样正确?我已经看到 bower_components
之后手动复制所有内容。当然,一定有更好的方法吧?
我最终通过调用这样配置的 copy
任务独立于 Bower 任务复制文件:
copy: {
main: {
files: [
{ expand: true, cwd: 'bower_components/', src: ['**'], dest: 'components/', filter: 'isFile' }, // bower components
]
}
}
当然,在这种情况下,必须重新配置 bower 任务,不要删除要从中复制的 bower 目录。
bower: {
install: {
options: {
targetDir: './components',
layout: 'byType',
install: true,
verbose: false,
cleanTargetDir: true,
cleanBowerDir: false,
bowerOptions: {}
}
}
}
这不是我真正希望的,但与此同时它完成了工作。