我使用NPM和Gulp作为我的包管理器和构建系统。 我已经安装了“gulp-sass”来支持sass和“gulp-clean-css”,这样我就可以@import嵌入css文件。 我在“_frontend/scss/**/*”中捕获我的SCSS文件,并将其编译为“assets/frontend/css/styles.css”单个文件。 在输出位置,我有其他重要的资源文件夹是“css”:“fonts”,“img”和“js”的兄弟。gulp-clean-css无法为资源(如字体和图像)设置url()的正确相对路径
我的问题是当我导入“* .css”文件时,我无法正确获取url()相对路径。 但是,当我导入“.scss”文件时可以。
这里是我的代码(我拿出sourcemaps,错误日志等,以简化的问题):
GULPFILE.JS
gulp.task('styles', function() {
gulp.src(styles.src)
.pipe(sassGlob()) // Support for bundle requires for Sass
.pipe(cleanCSS({
// relativeTo: './node_modules', <-- I tried with different variations here, no luck
// root: './node_modules', <-- I tried with different variations here, no luck
processImport: true
}))
.pipe(rename('styles.css')) // Name output CSS file
.pipe(gulp.dest('../assets/frontend/css/'));
});
MAIN.SCSS
以下是好的
@import "font-awesome/scss/font-awesome.scss";
输出似乎出来以正确的相对路径 示例输出:URL(?../字体/ FontAwesome/fontawesome-webfont.eot V = 4.6.1)
以下是NOT
@import '../node_modules/jquery-ui/themes/base/jquery-ui.css';
示例输出:URL(../ node_modules/jQuery的UI /主题/碱/图像/动画-overlay.gif) ^^上面以某种方式追加 “../node_modules” 。 我希望它以某种方式将其设置为“../img/vendor/jquery-ui/what/ever/i/like/here”
这里是我的目录结构。
_frontend
├─fonts
│ ├─Beamstyle-Icons
│ └─Gotham-Light-Regular
├─node_modules
│ ├─jquery-ui
│ │ ├─scripts
│ │ └─themes
│ │ ├─base
│ │ ├─images
│ │ └─minified
│ │ └─images
│ └─ (other stuff...)
│
├─scripts
│ ├─app
│ └─vendor
└─scss
├─config
├─helpers
│ ├─classes
│ ├─functions
│ ├─mixins
│ └─placeholders
└─src
├─blocks
└─components
assets
└─frontend
├─css
├─fonts
├─img
│ ├─Beamstyle-Icons
│ ├─FontAwesome
│ └─Gotham-Light-Regular
└─js
将是巨大的,如果任何人都可以在此帮助。