alexarsh
alexarsh

Reputation: 5391

How to use foundation css with webpack and react?

My stack is Horizon + React. I want to use foundation 6 on my client side. I use webpack for my js, but when I try to use it with css, I get only the comment from the foundation css but no css.

My files are:

webpack.config.js:

const path = require('path');

var config = {
    context: __dirname + "/src",
    entry: "./js/main.js",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015']
                }
            },
            {
                test: /\.scss$/,
                loaders: ['style', 'css', 'sass']
            }
        ]
    },
    resolve: {
        modulesDirectories: ['./node_modules']
    },
};
module.exports = config;

main.scss:

@import "../../node_modules/foundation-sites/scss/foundation";

main.js:

...
//adding css
require("../css/main.scss");
...

On the webpage i see only:

/**
 * Foundation for Sites by ZURB
 * Version 6.2.3
 * foundation.zurb.com
 * Licensed under MIT Open Source
 */

So what am I doing wrong?

Upvotes: 2

Views: 6928

Answers (2)

rafibomb
rafibomb

Reputation: 535

In terms of Webpack - 6.4 will ship with Webpack support https://github.com/zurb/foundation-sites/pull/9965

Upvotes: 1

Jonny Buchanan
Jonny Buchanan

Reputation: 62793

You need to @include the pieces you want to use. For example, to include everything:

@include foundation-everything;

Relevant docs are here:

Bonus tip: Webpack allows you to use ~ to import from module directories:

@import "~foundation-sites/scss/foundation";
@include foundation-everything;

Upvotes: 7

Related Questions