React-toolbox how to include the styles correctly

久未见 提交于 2019-12-01 21:00:36

You need to include modules (which unfortunately may break any other styling not using modules).

See https://github.com/react-toolbox/react-toolbox/issues/121 for more info.

This is the line you will need to utilize in your webpack loader:

require.resolve('css-loader') + '?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',

It looks like a Webpack config issue. It is actually weird because if webpack is not able to import the styles it should raise an import error instead of resolving an empty object. Since we cannot see the whole configuration file, I'd like to ask you if you already checked the working example repository: https://github.com/react-toolbox/react-toolbox-example

There is an example Webpack configuration, hope it helps!

oshaiken

its clear that webpack does not see the css/scss files, do you have any errors, if you look into that you will find the problem.

  1. problem might be that you need to install the css-loader and sass loader

    npm install css-loader --save-dev
    npm install sass-loader node-sass webpack --save-dev
    
  2. if you have done that try to resolve

    resolve: {extensions: ['', '.jsx', '.scss', '.js', '.json'],
        modulesDirectories: [
            'node_modules',
            ${process.cwd()}/node_modules
        ]
    },
    
  3. module: {
        loaders: [
            {
                test: /(\.js|\.jsx)$/,
                exclude: /(node_modules)/,
                loader: 'babel',
            },  {
                test: /(\.scss|\.css)$/,
                loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass'),
            },
            { test: /\.png$/, loader: "url-loader?limit=100000" },
            { test: /\.jpg$/, loader: "file-loader" },
        ]
    },
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!