question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overriding loader styles in webpack

See original GitHub issue

Hello,

I’m trying to override webpack configuration so I can add some options on css-loader and postcss-loader. However I run into an issue that says:

./src/components/mycomponent/MyComponent.css
Module build failed: Syntax Error

(5:1) Unknown word

  3 | // load the styles
  4 | var content = require("!!../../../node_modules/css-loader/index.js?{\"importLoaders\":1,\"modules\":true,\"localIdentName\":\"[name]__[local]___[hash:base64:5]\",\"camelCase\":true}!../../../node_modules/postcss-loader/lib/index.js!./MyComponent.css");

after reading some issues over css-loader. It looks like the issue is that I’m overriding the styles that you already defined on razzle conf (see https://stackoverflow.com/questions/37031123/why-am-i-not-being-able-to-compile-sass-with-webpack) and that doesn’t go well. I guess that’s why Vue created vue-loader.

Given my scenario, should it be best just to fork your project and start from there?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
d4rky-plcommented, Oct 5, 2017

@imjared I’ve been collecting helpers for razzle.config.js and putting them in module called razzle-config-utils so I don’t have to write the same find/findIndex hacks over multiple projects. You can check it out and see if it helps 😃

What you’re trying here would be possible with:

const { modifyRule } = require('razzle-config-utils')

module.exports = {
  modify: (config, {target, dev}, webpack) => {
    const appConfig = Object.assign({}, config);
    modifyRule(appConfig, { test: /\.css$/ }, (rule) => {
      rule.use = [
        'style-loader',
        { loader: 'css-loader', options: { modules: true, importLoaders: 1 } }, 
        'postcss-loader'
      ]
    })
    return appConfig;
  }
}

BTW, you’re mixing (very?) old webpack 1.x syntax with the new one - css should be css-loader and you should no longer specify your configuration as ?query&string but use options instead.

1reaction
d4rky-plcommented, Jul 5, 2017

@jaredpalmer oh yeah, it’d be perfect 😃 I was actually planning to release this config (probably tomorrow) with some tweaks and configurability as npm package so it can be used in a simliar fashion to my-razzle-modifictions from README 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

style-loader - webpack
Allows to setup absolute path to custom function that allows to override default behavior and insert styles at any position. Warning. Do not...
Read more >
Webpack can't fix CSS override issue and bundle <style ...
One solution is to enable local scoped css to avoid styles bleeding/overrides. Update your css-loader options to include modules: true
Read more >
css-module-override-webpack-plugin - npm
It loads CSS module overrides according to a file pattern and creates additional stylesheet files.
Read more >
Devon Govett on Twitter: "I tried overriding the webpack config ...
I tried overriding the webpack config to add style-loader and css-loader, but then I get a syntax error like it's trying to treat...
Read more >
Custom Webpack config | Remotion | Make videos ...
You can override it reducer-style by creating a function that takes the previous Webpack configuration and returns the the new one.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found