개발 환경에서의 트러블슈팅은 주로 소스 코드와 config, 패키지 변경에서 이뤄졌습니다.
%env_variable%
제거 (참고: 4.2.0 버전부터 지원됩니다)<script type="module" src="/src/index.tsx"></script>
@import ~
@vitejs/plugin-react-refresh
import { loadEnv } from 'vite';
const env = loadEnv(mode, process.cwd(), '');
// defineConfig 내 json 설정
define: {
__APP_ENV__: env.APP_ENV,
'process.env': env,
},
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
// defineConfig 내 json 설정
plugins: [viteCommonjs()]
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const webpackDevClientEntry = require.resolve('react-dev-utils/webpackHotDevClient');
const reactRefreshOverlayEntry = require.resolve('react-dev-utils/refreshOverlayInterop');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, '/dist'),
filename: 'index_bundle.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_module/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(svg|png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputhPath: 'imgs',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new ReactRefreshWebpackPlugin({
overlay: {
entry: webpackDevClientEntry,
module: reactRefreshOverlayEntry,
},
}),
],
};
import { defineConfig, loadEnv } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import viteCommonjs from 'vite-plugin-commonjs';
export default defineConfig(({ command, mode }) => {
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [reactRefresh(), viteCommonjs()],
root: './',
define: {
__APP_ENV__: env.APP_ENV,
'process.env': env,
},
base: '/',
build: {
outDir: './build',
manifest: true,
rollupOptions: {
input: 'index.html',
output: {
dir: './build',
format: 'esm',
},
},
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
}
};
});
글 작성을 염두에 두지 못하고 뒤늦게 정리하다보니 내용이 미흡해서 아쉽네요. 누군가에게는 도움이 되길 바랍니다.