我正在尝试将前端依赖项移出版本控制系统。Bower.io和Grunt的组合应该能够做到这一点。
然而,我遇到了一个问题,那就是我还无法通过捆绑多个供应商库来解决。例如,假设我有以下目录结构,其中components目录是Bower.io保存依赖项的目录:
├── assets
└── components
├── bootstrap
│ ├── img
│ │ └── glyhs.gif
│ └── less
│ └── bootstrap.css
└── jquery-ui
├── css
│ └── style.css
└── images
├── next.gif
└── prev.gif
现在假设我想捆绑jQuery的style.css和Bootstrap的bootstrap.css。我将把这个捆绑后的文件保存在assets/bundled.css中。
然而,在这个文件中,对原始图片(../images/next.gif和../img/glyhs.gif)的引用是不正确的。它们必须被重新编写以使其正常工作(所以../images/next.gif => ../components/jquery-ui/images/next.gif)。我相信重新编写URL是Grunt应该能够做到的事情。但是,使用cssmin/less/copy任务,我似乎无法让它工作。例如,以下Grunt设置(仅移动1个文件)无法工作:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
options: {
compile: false,
relativeUrls: true
},
bootstrap: {
src: 'components/bootstrap/less/bootstrap.less',
dest: 'assets/bootstrap.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('dist-css', ['less']);
};
两种可能:
我是否配置Grunt出错或者做错了什么?
或者我描述的工作流程不正确,应该使用其他替代方案。
谢谢!