我使用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
將是巨大的,如果任何人都可以在此幫助。