본문 바로가기
Front-End

[Next.js] Next에서 config 설정

by Judy 2022. 3. 18.
/** @type {import('next').NextConfig} */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true',
});
const withPlugins = require('next-compose-plugins');
const withAntdLess = require('next-plugin-antd-less');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const withAntdLessConfig = {
    // optional
    modifyVars: { '@primary-color': '#348fe2' },
    // optional
    lessVarsFilePath: './pages/antd-custom.less',
    // optional
    lessVarsFilePathAppendToEndOfContent: false,
    // optional https://github.com/webpack-contrib/css-loader#object
    cssLoaderOptions: {},

    // Other Config Here...

    future: {
        // if you use webpack5
        webpack5: true,
    },
};
const plugins = [
    // [withBundleAnalyzer],
    [withAntdLess, withAntdLessConfig],
];
const nextConfig = {
    webpack: (config, { webpack }) => {
        const prod = process.env.NODE_ENV === 'production';
        const newConfig = {
            ...config,
            mode: prod ? 'production' : 'development',
        };
        if (prod) {
            newConfig.devtool = 'hidden-source-map';
        }
        return newConfig;
    },
    async rewrites() {
        return [
            {
                source: '/:path*',
                destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`,
            },
        ];
    },
};

module.exports = withPlugins(plugins, nextConfig);


module.exports = {
  reactStrictMode: true,
}
// .env
NODE_ENV="development"
ENV_LOCAL_VARIABLE="server_only_variable_from_env_local"
NEXT_PUBLIC_ENV_LOCAL_VARIABLE="public_variable_from_env_local"
NEXT_PUBLIC_API_URL="http://dev.api2.test.co.kr"
NEXT_PUBLIC_IMAGE_URL="https://test.co.kr/web/images"

'Front-End' 카테고리의 다른 글

[Next.js] Next 13  (0) 2022.11.24
[Next.js] 최근 검색어 저장 (localStorage)  (0) 2022.05.24
[React-Native] React-native 설치하기  (0) 2022.02.28
[React Query] React Query와 상태관리  (0) 2022.02.23
[Next.js] .env (dotenv-webpack)  (0) 2022.02.10