Socket
Book a DemoInstallSign in
Socket

css-file-loader

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-file-loader

[![npm][npm]][npm-url] [![deps][deps]][deps-url]

latest
Source
npmnpm
Version
1.4.3
Version published
Maintainers
1
Created
Source

npm deps

CSS File Loader

Installation

  npm i --save-dev css-file-loader

How it works

This loader clones files (images, fonts ...) which referenced from css file like url (./image.png).

.selector {
    background: url(./img.png) no-repeat -122px -293px;
    width: 16px;
}

it will be replaced by

.selector {
    background: url([options.publicPath]/[file hash].png) no-repeat -122px -293px; 
    /*For example url(http://localhost/ad31..2a.png)  */
    width: 16px;
}

and [file hash].png will copy to output.path folder and filename replaced by file hash [file hash].png

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'css-loader', 'css-file-loader' ]
      }
    ]
  }
}

Combine with other loaders like sass

Important: css-file-loader must be before sass-loader

...
    rules: [
      {
        test: /\.scss$/,
        use: [ 'css-loader', 'css-file-loader', 'sass-loader' ]
      }
    ]
...

Options

NameTypeDefaultDescription
publicPath{String}output.publicPath or / if options.publicPath and output.publicPath are emptyThis option specifies the public URL of the output directory when referenced in a browser.Must have slash at the end /hello/

Usage with options

{
    test: /\.scss$/,
    use: [
        {loader: "css-loader"},
        {
            loader: "css-file-loader", options: {
                publicPath: "/hello/" ,
            }
        },
        {loader: "sass-loader"}
    ]
}

Keywords

webpack

FAQs

Package last updated on 29 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts