inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[리뉴얼] React로 NodeBird SNS 만들기

Antd / Less and Sass / CSS modules 설정 질문입니다

667

maliethy

작성한 질문수 9

0

AOS라는 라이브러리를 사용하고 싶어 cssModule을 사용해야 하는데

 import 'aos/dist/aos.css';

   antd customizing Theme을 위해 @zeit/next-less을 사용한 상태여서 cssModule 사용이 불가능하다고 합니다. 

 

이런 경우 공식문서(https://github.com/vercel/next-plugins/tree/master/packages/next-less)에서는 

  

// next.config.js

 

const withLess = require('@zeit/next-less')

 

module.exports = withLess({

 

  cssModules: true,

 

  cssLoaderOptions: {

 

    importLoaders: 1,

 

    localIdentName: "[local]___[hash:base64:5]",

 

  }

 

})

 

이런 식으로 설정하면 된다고 나와있어서 시도해보았지만 여전히 css 파일을 못읽어 module parse error가 나왔습니다.

 그래서 @zeit/next-css를 적용시켜보니 css파일을 읽혀지지만 antd 기본 디자인이 적용되지 않는 문제가 발생했습니다.

 

 /next.config.js

 

const withCSS = require('@zeit/next-css');

 

const withLess = require('@zeit/next-less');

 

 

 

module.exports = withCSS(withLess({

 

    lessLoaderOptions: {

 

        javascriptEnabled: true,

 

 

 

    },

 

    cssModules: true,

 

    cssLoaderOptions: {

 

        importLoaders: 3,

 

        localIdentName: '[local]___[hash:base64:5]'

 

    },

 

    distDir: '.next',

 

    webpack(config, { webpack }) {

 

        const prod = process.env.NODE_ENV === 'production';

 

        const newConfig = {

 

            ...config,

 

            mode: prod ? 'production' : 'development',

 

            plugins: [

 

                ...config.plugins,

 

                new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /^\.\/ko$/),

 

            ],

 

        }

 

        if (prod) {

 

            newConfig.devtool = 'hidden-source-map';

 

        }

 

        return newConfig;

 

    },

 

}));

 

비슷한 경우가  있어서 따라해보았지만

'How to configure Next.js with Antd / Less and Sass / CSS modules'

 https://stackoverflow.com/questions/61240582/how-to-configure-next-js-with-antd-less-and-sass-css-modules 

이 경우 또한 module parse error가 나왔습니다.

/next.config.js

 const withLess = require('@zeit/next-less');

const withSass = require('@zeit/next-sass');

const lessToJS = require('less-vars-to-js');

const fs = require('fs');

const path = require('path');

 

// Where your antd-custom.less file lives

const themeVariables = lessToJS(

    fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8')

);

 

module.exports = withSass({

    cssModules: true,

    ...withLess({

        lessLoaderOptions: {

            javascriptEnabled: true,

            modifyVars: themeVariables, // make your antd custom effective

            importLoaders: 0

        },

        cssLoaderOptions: {

            importLoaders: 3,

            localIdentName: '[local]___[hash:base64:5]'

        },

        webpack: (config, { isServer }) => {

            //Make Ant styles work with less

            if (isServer) {

                const antStyles = /antd\/.*?\/style.*?/;

                const origExternals = [...config.externals];

                config.externals = [

                    (context, request, callback) => {

                        if (request.match(antStyles)) return callback();

                        if (typeof origExternals[0] === 'function') {

                            origExternals[0](context, request, callback);

                        } else {

                            callback();

                        }

                    },

                    ...(typeof origExternals[0] === 'function' ? [] : origExternals)

                ];

 

                config.module.rules.unshift({

                    test: antStyles,

                    use: 'null-loader'

                });

            }

            return config;

        }

    })

});

 

1. antd 기본 스타일을 유지한 채

2. them customizing을 위해 @zeit/next-less을 사용하면서 

3. cssModule 사용도 가능하려면

 next.config.js를 어떤 식으로 설정해야 될까요?

 

 

 

 

redux react express nodejs Next.js

답변 1

1

제로초(조현영)

플러그인이 많아지는 경우

https://github.com/cyrilwanner/next-compose-plugins#readme

를 사용해서 플러그인 설정을 개별적으로 적용하시는 것을 추천드립니다.

이걸로 설정을 해보시고 안 되면 다시 남겨주세요.

넥스트 버젼 질문

0

77

2

로그인시 401 Unauthorized 오류가 뜹니다

0

89

1

무한 스크롤 중 스크롤 튐 현상

0

174

1

특정 페이지 접근을 막고 싶을 때

0

103

2

createGlobalStyle의 위치와 영향범위

0

96

2

인라인 스타일 리렌더링 관련

0

91

2

vsc 에서 npm init 설치시 오류

0

146

2

nextjs 15버전 사용 가능할까요?

0

158

1

화면 새로고침 문의

0

121

1

RTK에서 draft, state 차이가 있나요?

0

153

2

Next 14 사용해도 될까요?

0

452

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

349

1

url 오류 질문있습니다

0

211

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

372

1

sudo certbot --nginx 에러

0

1273

2

Minified React error 콘솔에러 (hydrate)

0

469

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

247

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

326

1

npm run build 에러

0

518

1

front 서버 npm run build 중에 발생한 에러들

0

381

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

337

2

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

0

286

1

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

237

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

201

1