Next.js - import css file does not work

后端 未结 6 739
北荒
北荒 2021-02-18 22:31

I am creating a project with react, redux and next.js, and want to import CSS files in js.

I followed instructions in next.js/#css and next-css, but find out that CSS st

6条回答
  •  感动是毒
    2021-02-18 23:07

    If you use next.js do this.

    create next.config.js in root projects

    const withCSS = require('@zeit/next-css');
    
    function HACK_removeMinimizeOptionFromCssLoaders(config) {
        console.warn(
            'HACK: Removing `minimize` option from `css-loader` entries in Webpack config',
        );
        config.module.rules.forEach(rule => {
            if (Array.isArray(rule.use)) {
                rule.use.forEach(u => {
                    if (u.loader === 'css-loader' && u.options) {
                        delete u.options.minimize;
                    }
                });
            }
        });
    }
    
    module.exports = withCSS({
        webpack(config) {
            HACK_removeMinimizeOptionFromCssLoaders(config);
            return config;
        },
    });
    

    Don't forget to restart the server

提交回复
热议问题