WEB/Vue.js

[Vue.js] Vue-cli ์™€ webpack-bundle-analyzer

S0PH1A 2021. 6. 23. 01:24
๋ฐ˜์‘ํ˜•

[Vue.js] Vue-cli ์™€ webpack-bundle-analyzer


 

๐Ÿ‘ฉ‍๐Ÿ’ป webpack-bundle-analyzer

webpack-bundle-analyzer๋Š” ์›นํŒฉ์„ ํ†ตํ•ด ๋ฒˆ๋“ค๋ง๋˜๋Š” ๋ชจ๋“ˆ์˜ ํฌ๊ธฐ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณด์—ฌ์ค€๋‹ค.

๋ฒˆ๋“ค ํŒŒ์ผ์˜ ์šฉ๋Ÿ‰์„ ํ™•์ธํ•จ์œผ๋กœ์จ ๋ฒˆ๋“ค ํฌ๊ธฐ์— ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๋ฒˆ๋“ค์„ ํ™•์ธํ•˜๊ณ  ์ค„์ผ ์ˆ˜ ์žˆ๋„๋ก ํ•˜์—ฌ ์†๋„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋„๋ก ๋„์›€์„ ์ค€๋‹ค.

 

webpack-bundle-analyzer

 

 

โ›๏ธ ์„ค์ •ํ•˜๊ธฐ

๊ธฐ๋ณธ์ ์œผ๋กœ build ๋ฅผ ํ•˜๊ฒŒ๋˜๋ฉด ์ž๋™์œผ๋กœ ์‹คํ–‰๋˜๋ฉฐ, pluginOptions.webpackBundleAnalyzer์— ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

// vue.config.js
pluginOptions: {
    webpackBundleAnalyzer: {
        // ์ด๊ณณ์— webpack-bundle-analyzer ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.
        analyzerMode: "static"  // ๊ฒฐ๊ณผ๋ฅผ ํŒŒ์ผ๋กœ ์ €์žฅ
    }
},

ํŒŒ์ผ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ dist/report.html ๋กœ ์ €์žฅ๋œ๋‹ค.

vue-cli-service build ์˜ต์…˜ ์ค‘ --report ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด analyzerMode: "static" ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ ๋„ ๊ฒฐ๊ณผ๋ฅผ ํŒŒ์ผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.

$ npm run build --report

[์ฐธ๊ณ : vue-cli-service-build] https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-build

[์ฐธ๊ณ : webpack-bundle-analyzer ์˜ต์…˜] https://github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin

 

 


๋‚˜๋Š” analyzerMode๋ฅผ disabled ํ•˜์—ฌ ํ”„๋กœ๋•์…˜ ๋นŒ๋“œ์‹œ์—๋Š” ๋ถ„์„์„ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ , build-report ์˜ต์…˜์„ ์ด์šฉํ–ˆ์„ ๋•Œ์—๋งŒ ์‹คํ–‰ํ•˜๋„๋ก ์„ค์ •ํ•ด์„œ ์‚ฌ์šฉํ–ˆ๋‹ค.

// package.json
{
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "build:report": "vue-cli-service build --report"  // ์ถ”๊ฐ€
  },
}
$ npm run build:report

 

 

๋ฐ˜์‘ํ˜•