Skip to content

Prevent css-loader from requiring urls but also prepend root #604

@no1melman

Description

@no1melman

I have my folder structure like so:

myApp
 +-- src
 |     |-- index.js
 |     |-- index.css
 +-- resources
 |     |-- fonts
 |     +-- images
 |     |     |-- portrait.png
 |     |     |-- bg.png

My webpack I have this

rules: [
    {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: { loader: 'css-loader', options: { url: true, root: 'http://localhost:8080/' } }
        }),
        exclude: /node_modules/
    },
    {
        test: /(\.png|\.jpg|\.otf)$/,
        use: ['file-loader?name=[name].[ext]&publicPath=assets/&outputPath=assets/']
    }
]

In the index.js file I have this

import './resources/images/portrait.png' // <- this is handled by the file loader
import './index.css' // <- this should be handled by the ExtractTextPlugin and css-loader
// blah blah
export default Index;

In the index.css file I have this:

.background {
    background: url('/assets/portrait.png') 0 center;
}

So I have to have { url: true } in order for the { root: 'http://localhost:8080/' } to be prepended - however, it seems like it's trying to make a js module and requiring in the asset, which isn't what I want.....

Is there anyway to prevent the css-loader from trying to resolve the url but still have the root prepended

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions