arc icon indicating copy to clipboard operation
arc copied to clipboard

Style Loader

Open ajhool opened this issue 8 years ago • 11 comments

Any interest in adding a css style loader to webpack by default? I believe the dependency is:

npm install --save-dev css-loader

With the most basic rule added to webpack.config.js :

      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }

ajhool avatar Mar 24 '17 19:03 ajhool

Actually, the above code was only working in storybook, but it seems to be a far more complicated task to properly import css and scss into the isomorphic framework. CSS import seems to be a bleeding edge issue and I haven't found a successful configuration for this framework yet. Has anybody else had luck?

ajhool avatar Mar 24 '17 21:03 ajhool

I installed the following dependencies, and then added them to webpack.config.js -

      {
        test: /\.scss$/,
        loader: 'style-loader!css-loader!resolve-url-loader!sass-loader?sourceMap'
      }

And in the component files, i use ES5 requires, to import the scss file.

mininternet avatar Mar 25 '17 01:03 mininternet

FYI this is exclusively an issue with the server aspect of getting the stylesheet.

I sort of ran into this problem as well, and was able to get it working by doing the following:

if (typeof window === 'object') {
  require('./styles.css')
}

But as you probably know, that means server-side rendering wont happen. My pages had a brief period where no styles were displayed, and then they showed up after initial load.

Back to the drawing board!

mrsteele avatar Mar 28 '17 19:03 mrsteele

@ajhool Do you mean adding css modules functionality along with styled-components?

Also, I'm not too certain if this will have an impact, but it looks like the react-router v4 pull is going to be merged soon, so the way you hook this up to server rendering may change as well.

protoEvangelion avatar Mar 31 '17 00:03 protoEvangelion

I am attempting to load the CSS for the https://github.com/davidchin/react-input-range component. I have followed @mininternet’s suggestion to install dependencies and add to the webpack, but I am unsure whether this belongs in the babel set, the assets set, or …?

Either way, I get this message:

ERROR in ./~/react-input-range/lib/css/index.css
Module parse failed: /Users/username/sites/myProject/node_modules/react-input-range/lib/css/index.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .input-range__slider { // more CSS follows

Any advice would be greatly appreciated.

EricWVGG avatar Nov 06 '17 21:11 EricWVGG

This sounds to me like an issue with that particular package, rather than the webpack loaders.

mininternet avatar Nov 09 '17 05:11 mininternet

I can't rule that out, but I also still don't know whether these webpack rules go in Babel, Assets, something else, and I have had no luck with other components to boot.

EricWVGG avatar Nov 09 '17 16:11 EricWVGG

@EricWVGG - they go in webpackconfig.js. I've updated my comment above to reflect that. But this is really more a webpack configuration issue rather than anything to do specifically with ARc.

mininternet avatar Nov 09 '17 20:11 mininternet

"I have followed @mininternet’s suggestion to install dependencies and add to the webpack, but I am unsure whether this belongs in the babel set, the assets set"

const babel = () => () => ({
  module: {
    rules: [
      { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader' },
    ],
  },
})

const assets = () => () => ({
  module: {
    rules: [
      { test: /\.(png|jpe?g|svg|woff2?|ttf|eot)$/, loader: 'url-loader?limit=8000' },
    ],
  },
})

EricWVGG avatar Nov 09 '17 21:11 EricWVGG

Successfully able to add like this,

npm install --save-dev style-loader css-loader sass-loader node-sass or yarn add -D style-loader css-loader sass-loader node-sass

in webpack.config.js file edit

const assets = () => () => ({
  module: {
    rules: [
      {test: /(\.css|\.scss)$/, loaders: ['style-loader', 'css-loader?sourceMap', 'sass-loader?sourceMap']},
      { test: /\.(png|jpe?g|svg|woff2?|ttf|eot)$/, loader: 'url-loader?limit=8000' }
    ],
  },
})

hope this help others, thx and keep up the good work

sasajib avatar Jan 27 '18 23:01 sasajib

@sasajib but it's will not work with isomorphic app

pgrekovich avatar Feb 04 '18 21:02 pgrekovich