16. Vue JS/Vue 2

06. Vue 2 - TerserPlugin 을 이용한 웹 팩 설정

THE HEYDAZE 2020. 9. 23. 04:23
OS Windows 10 Home 64bit 버전 1903 (OS 빌드 18362.836)
Vue 2.5.13

 

# 참고
 

Environment Variables | Cracking Vue.js

환경 변수 파일을 이용한 옵션 설정 환경 변수 파일이란 애플리케이션이 실행될 때 특정 값을 넘길 수 있는 변수를 의미합니다. 웹 애플리케이션 관점에서는 .env 파일에 정의된 변수를 의미하며

joshua1988.github.io

 

 

vue 실행 모드와 환경 변수 설정

뷰의 실행모드와 환경 변수를 설정하는 방법에 대해 알아봅시다.참고 링크: Modes and Environment Variables(https://cli.vuejs.org/guide/mode-and-env.html로컬에서는 http://localhost

velog.io

 

Vue.config.js 설정

const TerserPlugin = require('terser-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production'

module.exports = {
    /** 서버 설정 */
    devServer: {
        port: 3000,
        proxy: {
            'api/*': {
                target: 'http://localhost:8080'
            }
        }
    },
    /** 웹 팩 설정*/
    configureWebpack: {
        optimization: {
            minimize: true,
            minimizer: isProd ? [
                new TerserPlugin({
                    terserOptions: {
                        ecma: 6,
                        compress: { drop_console: true },
                        output: { comments: false, beautify: false }
                    }
                })
            ] : []
        }
    },
    /** 플러그인 옵션 */
    pluginOptions: {
        i18n: {
            locale: 'kor',
            fallbackLocale: 'kor',
            localeDir: 'locales/messages',
            enableInSFC: false
        }
    },
}

 

development, test, production 모드가 있는 데 기본모드는 development 이다

production 모드 인 경우 console.log 구문은 모두 제거되어 빌드 된다

 

# env 설정법

[방법1] 터미널 창

npm run serve --mode production

 

[방법2] package.json 

 

[방법3] 인텔리제이 창

'16. Vue JS > Vue 2' 카테고리의 다른 글

09. Vue 2 - vuedraggable 2.24  (4) 2020.09.24
08. Vue 2 - Router 현재 페이지 갱신  (0) 2020.09.23
07. Vue 2 - logger 플러그인  (0) 2020.09.23
04. Vue 2 - Axios Cross Origin 설정  (0) 2020.09.21
03. Vue 2 - 스토리 북 (Storybook)  (1) 2020.09.15