css-loader-relative
v0.0.5
Published
css-loader replace url to relative
Downloads
4
Readme
css-loader-relative
css-loader replace url to relative path
https://github.com/xxxxst/css-loader-relative
//input
@import "/src/assets/css/style.css"
.home{background: url("/static/image.png");}
//output
@import "assets/css/style.css"
.home{background: url("./static/image.png");}
npm install --save-dev css-loader-relative
keep this plugin before scss-loader
Vue
build/utils.js
exports.cssLoaders = function(options) {
options = options || {}
const cssLoader = { ... }
const cssLoaderRelative = {
loader: 'css-loader-relative'
}
function generateLoaders(loader, loaderOptions) {
const loaders = options.usePostCSS
? [cssLoader, postcssLoader]
: [cssLoader];
if(loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
});
// add plugin at here
loaders.push(cssLoaderRelative);
}
...
}
}
License
Copyright (c) 2018-present, xxxxst