Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor CSS not importing #96

Closed
zeroasterisk opened this issue Apr 11, 2016 · 15 comments
Closed

Meteor CSS not importing #96

zeroasterisk opened this issue Apr 11, 2016 · 15 comments

Comments

@zeroasterisk
Copy link

I'm following your docs/guide for CSS importing, from a Meteor app, and I am not getting the CSS into React Storybook, but it is in my Meteor app... and both are running at the same time.

$ npm -v && node -v
3.8.5
v4.2.1
$ npm install --save-dev style-loader raw-loader
// .storybook/webpack.config.js
const path = require('path');

module.exports = {
  module: {
    loaders: [
      {
        test: /\.css?$/,
        loaders: [ 'style', 'raw' ],
        include: path.resolve(__dirname, '../')
      }
    ]
  }
}

// .storybook/config.js
import { configure } from '@kadira/storybook';

function loadStories() {
  require('../imports/ui/layouts/stories/Header.jsx');
  require('../imports/ui/layouts/stories/Footer.jsx');
}

configure(loadStories, module);

React Storybook has no CSS files loading via Chrome Inspector Network.

@arunoda
Copy link
Member

arunoda commented Apr 11, 2016

See here: https://github.com/mantrajs/mantra-sample-blog-app/blob/master/client/modules/core/components/.stories/index.js#L1

You need to import CSS inside the story files. You can also done that with config.js as well.

@zeroasterisk
Copy link
Author

OK great, thanks... Will that work for '.less' files too? How about module loaded frameworks like bootstrap?

@arunoda
Copy link
Member

arunoda commented Apr 11, 2016

For the less, you need to configure a less webpack loader.
In the boostrap case it doesnt work. You may can directly i
pory such bootstrap in the config.js with a help of a NPM bootstrap library.

@ffxsam
Copy link

ffxsam commented Apr 16, 2016

I came here for the same issue - trying to use SCSS with React Storybook.
https://forums.meteor.com/t/react-storybook-how-to-get-styling/21496

Is webpack the only solution?

@arunoda
Copy link
Member

arunoda commented Apr 16, 2016

@ffxsam Yep. That's the only way which supports hot loading.

@zeroasterisk
Copy link
Author

zeroasterisk commented Apr 19, 2016

Ok I finally got this working last night... thought I'd share.

Webpack builder + bootstrap + font-awesome + meteor .css files (need to change to .less builder soon)

This isn't perfect, and I think I might be duplicating effort a bit, but it's at least working.

// .storybook/webpack.config.js
const path = require('path');

module.exports = {
  entry: [
    'bootstrap-webpack!' + path.resolve(__dirname, './bootstrap.config.js'),
    'font-awesome-webpack!' + path.resolve(__dirname, './font-awesome.config.js')
  ],
  output: {
    path: path.join(__dirname, '../public'),
    filename: 'webpack-output.js'
  },
  //resolveLoader: { root: path.resolve(__dirname, '../node_modules') },
  module: {
    loaders: [
      {
        test: /\.css?$/,
        loaders: [ 'style', 'raw' ],
        include: path.resolve(__dirname, '../')
      },
      { test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery' },
      { test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/,   loader: 'file-loader?limit=10000&mimetype=application/font-woff' },
      { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,    loader: 'file-loader?limit=10000&mimetype=application/octet-stream' },
      { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,    loader: 'file' },
      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,    loader: 'file-loader?limit=10000&mimetype=image/svg+xml' }
    ]
  }
};

// .storybook/config.js
import { configure } from '@kadira/storybook';

function loadStories() {
  require('bootstrap-webpack');
  require('font-awesome-webpack');
  require('../imports/ui/layouts/stories/Header.jsx'); // <-- includes app css
  ...
}

// .storybook/font-awesome.config.js
module.exports = {
  // Default for the style loading
  styleLoader: 'style-loader!css-loader!less-loader',

  styles: {
    'mixins': true,
    'bordered-pulled': true,
    'core': true,
    'fixed-width': true,
    'icons': true,
    'larger': true,
    'list': true,
    'path': true,
    'rotated-flipped': true,
    'animated': true,
    'stacked': true
  }
};

// .storybook/font-awesome.config.js
module.exports = {
  scripts: {
    // add every bootstrap script you need
    'transition': true
  },
  styles: {
    // add every bootstrap style you need
    'mixins': true,
    'normalize': true,
    'print': true,
    'scaffolding': true,
    'type': true
  }
};

@ffxsam
Copy link

ffxsam commented Apr 19, 2016

Boggles my mind why people like webpack so much.. ugh. All that, just to get everything working?

@arunoda I would recommend maybe adding a webpack config to the package so that Sass & LESS work out of the box, as I'm willing to bet there are lots of projects that don't use plain CSS.

@arunoda
Copy link
Member

arunoda commented Apr 19, 2016

We can add a link to above when we are talking about CSS in Meteor. We won't bundle anything default related to CSS with Storybook.

I hope that's the best way.

@ffxsam
Copy link

ffxsam commented Apr 19, 2016

Ok, but even if you can have webpack boilerplate that we can copy/paste that will make CSS, Sass, and LESS work.. that would be awesome. Because lots of Meteor folks like myself haven't had a need to use webpack thanks to Meteor's build system, and the learning curve for webpack is massive. I know I don't have the time to invest in learning it.

@arunoda
Copy link
Member

arunoda commented Apr 19, 2016

@ffxsam Yes. We can simply put it there.

@ffxsam
Copy link

ffxsam commented Apr 19, 2016

Many thanks! 😀

@arunoda
Copy link
Member

arunoda commented Apr 19, 2016

@ffxsam BTW: Send me a PR, if you can do if before me.
I suggest to create a gist with the boileplate and link it with other info.

@ffxsam
Copy link

ffxsam commented Apr 19, 2016

Love to, but I don't know webpack - sorry!

@ickyrr
Copy link

ickyrr commented May 26, 2016

@zeroasterisk Thank you! That solved my problem.

@arunoda
Copy link
Member

arunoda commented Aug 3, 2016

We will use this or similar by default. We'll work on this with our new tool getstorybook. Closing this and moving the discussion here: storybook-eol/getstorybook#1

@arunoda arunoda closed this as completed Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants