
Published on June 09, 2024 by Eunbi.N
Vite Plugins Build Tools Performance Development
// webpack.config.js 예시
module.exports = {
entry: "./src/main.js",
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader",
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
],
};
# Webpack 관련 패키지 제거
npm uninstall webpack webpack-cli webpack-dev-server
npm uninstall vue-loader vue-template-compiler
npm uninstall html-webpack-plugin mini-css-extract-plugin
npm uninstall css-loader style-loader sass-loader
npm uninstall @babel/core @babel/preset-env babel-loader
# Vite 관련 패키지 설치
npm install --save-dev vite @vitejs/plugin-vue
npm install --save-dev sass
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
"~": resolve(__dirname, "src"),
components: resolve(__dirname, "src/components"),
views: resolve(__dirname, "src/views"),
assets: resolve(__dirname, "src/assets"),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `
@import "@/assets/styles/variables.scss";
@import "@/assets/styles/mixins.scss";
`,
},
},
},
server: {
port: 8080,
open: true,
cors: true,
proxy: {
"/api": {
target: "http://localhost:3000",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
strictPort: true, // 포트가 사용 중이면 실패
hmr: {
overlay: false, // 에러 오버레이 비활성화
},
},
build: {
outDir: "dist",
assetsDir: "assets",
sourcemap: true, // 디버깅
rollupOptions: {
output: {
manualChunks: {
"vue-vendor": ["vue", "vue-router"],
"ui-vendor": ["element-plus", "ant-design-vue"],
"utils-vendor": ["axios", "lodash", "moment"],
},
},
},
},
optimizeDeps: {
include: ["vue", "vue-router", "pinia", "axios", "lodash-es"],
exclude: ["@vueuse/core"], // 사전 번들링에서 제외
},
});
{
"scripts": {
"dev": "vite",
"serve": "vite",
"build": "vite build",
"preview": "vite preview",
"build:analyze": "vite build --mode analyze"
}
}
VITE_APP_TITLE=My Vue App (Development)
VITE_API_BASE_URL=http://localhost:3000/api
VITE_APP_VERSION=1.0.0
VITE_APP_TITLE=My Vue App
VITE_API_BASE_URL=https://api.myapp.com
VITE_APP_VERSION=1.0.0
const apiUrl = import.meta.env.VITE_API_BASE_URL;
const appTitle = import.meta.env.VITE_APP_TITLE;