├── renovate.json
├── commitlint.config.js
├── test
├── fixture
│ ├── custom
│ │ └── Custom.vue
│ ├── components
│ │ ├── Test.css
│ │ └── Test.vue
│ ├── pages
│ │ └── index.vue
│ └── configs
│ │ └── default.js
└── module.test.js
├── .gitignore
├── .eslintrc.js
├── .travis.yml
├── .editorconfig
├── CHANGELOG.md
├── LICENSE
├── lib
└── module.js
├── README.md
└── package.json
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@nuxtjs"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = { extends: ['@commitlint/config-conventional'] }
2 |
--------------------------------------------------------------------------------
/test/fixture/custom/Custom.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Custom
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.iml
3 | .idea
4 | *.log*
5 | .nuxt*
6 | .vscode
7 | .DS_STORE
8 | coverage
9 | dist
10 |
--------------------------------------------------------------------------------
/test/fixture/components/Test.css:
--------------------------------------------------------------------------------
1 | .abc {
2 | text-align: center;
3 | }
4 |
5 | .ymca {
6 | text-align: center;
7 | }
8 |
--------------------------------------------------------------------------------
/test/fixture/components/Test.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Test
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | parserOptions: {
4 | parser: 'babel-eslint',
5 | sourceType: 'module'
6 | },
7 | extends: [
8 | '@nuxtjs'
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8"
4 | - "9"
5 | - "10"
6 | - "11"
7 | cache:
8 | yarn: true
9 | directories:
10 | - node_modules
11 | install:
12 | - yarn
13 | script:
14 | - yarn test
15 | after_success:
16 | - yarn coverage
17 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_size = 2
6 | indent_style = space
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/test/fixture/pages/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Test
4 |
5 |
6 |
7 |
8 |
17 |
--------------------------------------------------------------------------------
/test/fixture/configs/default.js:
--------------------------------------------------------------------------------
1 | const { resolve } = require('path')
2 |
3 | module.exports = {
4 | rootDir: resolve(__dirname, '../../../'),
5 | srcDir: resolve(__dirname, '../'),
6 | modules: ['@@'],
7 | build: {
8 | quiet: false,
9 | analyze: true
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | ## [0.0.2](https://github.com/Developmint/nuxt-bundle-buddy/compare/v0.0.1...v0.0.2) (2018-11-22)
7 |
8 |
9 | ### Bug Fixes
10 |
11 | * disable on modern build ([397e524](https://github.com/Developmint/nuxt-bundle-buddy/commit/397e524))
12 |
13 |
14 |
15 |
16 | ## 0.0.1 (2018-11-02)
17 |
--------------------------------------------------------------------------------
/test/module.test.js:
--------------------------------------------------------------------------------
1 | const consola = require('consola')
2 | const { Nuxt, Builder } = require('nuxt-edge')
3 |
4 | jest.setTimeout(60 * 1000)
5 |
6 | let nuxt
7 |
8 | describe('nuxt-bundle-buddy', () => {
9 | beforeAll(() => {
10 | consola.wrapAll()
11 | })
12 |
13 | beforeEach(() => {
14 | jest.spyOn(process, 'exit').mockImplementationOnce(() => {})
15 | consola.mockTypes(() => jest.fn())
16 | })
17 |
18 | test('load bundle-buddy webpack plugin', async () => {
19 | try {
20 | nuxt = await setupNuxt(require('./fixture/configs/default'))
21 | } catch (e) {}
22 |
23 | const consolaMessages = consola.log.mock.calls.map(c => c[0])
24 | expect(consolaMessages.find(s => s.includes('No bundle duplication detected'))).toBeTruthy()
25 | })
26 |
27 | afterEach(async () => {
28 | if (nuxt) {
29 | await nuxt.close()
30 | }
31 | })
32 | })
33 | const setupNuxt = async (config) => {
34 | const nuxt = new Nuxt(config)
35 | await new Builder(nuxt).build()
36 |
37 | return nuxt
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Alexander Lichter
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/lib/module.js:
--------------------------------------------------------------------------------
1 | import consola from 'consola'
2 | import BundleBuddyWebpackPlugin from 'bundle-buddy-webpack-plugin'
3 |
4 | const logger = consola.withTag('nuxt-bundle-buddy')
5 |
6 | export default function nuxtBundleBuddy() {
7 | const { build: { analyze }, dev, bundleBuddy } = this.options
8 |
9 | const options = Object.assign({}, { removeDefaultAnalyzer: true }, bundleBuddy)
10 |
11 | if (!dev && analyze) {
12 | logger.info('Loading module')
13 | this.extendBuild(webpackFn(options))
14 | }
15 | }
16 |
17 | const webpackFn = options => (config, { isServer, isModern }) => {
18 | // Only evaluate client bundle
19 | if (isServer || isModern) {
20 | return
21 | }
22 |
23 | // Remove normal analyze plugin if option is set
24 | if (options.removeDefaultAnalyzer) {
25 | const pluginIndex = config.plugins.findIndex(p => p.constructor.toString().includes('BundleAnalyzer'))
26 | config.plugins.splice(pluginIndex, 1)
27 | }
28 |
29 | // Add bundle-buddy-plugin and **force sourcemaps**
30 |
31 | config.devtool = 'source-map'
32 | config.plugins.push(new BundleBuddyWebpackPlugin({ sam: true }))
33 | }
34 |
35 | module.exports.meta = require('../package.json')
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nuxt Bundle Buddy - Don't fight your webpack bundle, become friends!
2 | [](https://npmjs.com/package/nuxt-bundle-buddy)
3 | [](https://npmjs.com/package/nuxt-bundle-buddy)
4 | [](https://travis-ci.com/Developmint/nuxt-bundle-buddy)
5 | [](https://codecov.io/gh/Developmint/nuxt-bundle-buddy)
6 | [](https://david-dm.org/Developmint/nuxt-bundle-buddy)
7 | [](http://standardjs.com)
8 | [](https://thanks.lichter.io/)
9 |
10 | 
11 |
12 | [📖 **Release Notes**](./CHANGELOG.md)
13 |
14 | ## Features
15 |
16 | * Analyzes your bundle and visualize improvement opportunities
17 | * Built on top of [bundle-buddy](https://github.com/samccone/bundle-buddy)
18 | * Fully tested!
19 | * Nuxt 2 support
20 |
21 | ## Setup
22 |
23 | - Install [`bundle-buddy`](https://github.com/samccone/bundle-buddy) globally,
24 | **otherwise you won't see anything**
25 | - Add the `nuxt-bundle-buddy` dependency using yarn or npm to your project
26 | - Add `nuxt-bundle-buddy` to `modules` section of `nuxt.config.js`:
27 |
28 | ```js
29 | {
30 | modules: [
31 | 'nuxt-bundle-buddy',
32 | ],
33 |
34 | bundleBuddy: {
35 | // your settings here
36 | // Usually you don't need any though, so you can fully omit the
37 | // bundleBuddy object
38 | }
39 | }
40 | ```
41 |
42 | - Run a Nuxt analyze build (`yarn build --analyze` or `npm run build -- --analyze`)
43 |
44 | ## Options
45 |
46 |
47 | ```js
48 | // file: nuxt.config.js
49 | export default {
50 | bundleBuddy: {
51 | removeDefaultAnalyzer: true // disable to keep default webpack analyzer
52 | }
53 | }
54 | ```
55 |
56 | ## Development
57 |
58 | - Clone this repository
59 | - Install dependencies using `yarn install` or `npm install`
60 | - Start development server using `npm run dev`
61 |
62 | ## License
63 |
64 | [MIT License](./LICENSE)
65 |
66 | Copyright (c) Alexander Lichter
67 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-bundle-buddy",
3 | "version": "0.0.2",
4 | "description": "Don't fight your webpack bundle, become friends!",
5 | "license": "MIT",
6 | "contributors": [
7 | {
8 | "name": "Alexander Lichter "
9 | }
10 | ],
11 | "main": "lib/module.js",
12 | "repository": {
13 | "mode": "git",
14 | "url": "git+https://github.com/Developmint/nuxt-bundle-buddy"
15 | },
16 | "bugs": {
17 | "url": "https://github.com/Developmint/nuxt-bundle-buddy/issues"
18 | },
19 | "publishConfig": {
20 | "access": "public"
21 | },
22 | "scripts": {
23 | "dev": "nuxt build --config-file test/fixture/configs/default.js",
24 | "lint": "eslint lib test",
25 | "test": "yarn run lint && jest --detectOpenHandles",
26 | "release": "standard-version && git push --follow-tags && npm publish",
27 | "commitlint": "commitlint -E HUSKY_GIT_PARAMS",
28 | "coverage": "codecov",
29 | "webpack-defaults": "webpack-defaults",
30 | "defaults": "webpack-defaults"
31 | },
32 | "eslintIgnore": [
33 | "lib/templates/*.*"
34 | ],
35 | "files": [
36 | "lib"
37 | ],
38 | "keywords": [
39 | "nuxtjs",
40 | "nuxt",
41 | "nuxt-module",
42 | "bundle-buddy",
43 | "webpack",
44 | "visualize"
45 | ],
46 | "engines": {
47 | "node": ">=8.0.0",
48 | "npm": ">=5.0.0"
49 | },
50 | "jest": {
51 | "testEnvironment": "node",
52 | "collectCoverage": true,
53 | "coveragePathIgnorePatterns": [
54 | "/node_modules/",
55 | "/test/fixture"
56 | ],
57 | "forceExit": true
58 | },
59 | "dependencies": {
60 | "bundle-buddy-webpack-plugin": "^0.3.0",
61 | "consola": "2.3.0"
62 | },
63 | "devDependencies": {
64 | "@commitlint/cli": "^7.2.1",
65 | "@commitlint/config-conventional": "^7.1.2",
66 | "@nuxtjs/eslint-config": "^0.0.1",
67 | "babel-eslint": "^10.0.1",
68 | "codecov": "^3.1.0",
69 | "eslint": "^5.10.0",
70 | "eslint-config-standard": "^12.0.0",
71 | "eslint-plugin-import": "^2.14.0",
72 | "eslint-plugin-jest": "^22.1.2",
73 | "eslint-plugin-node": "^8.0.0",
74 | "eslint-plugin-promise": "^4.0.1",
75 | "eslint-plugin-standard": "^4.0.0",
76 | "eslint-plugin-vue": "^5.0.0",
77 | "husky": "^1.2.0",
78 | "jest": "^23.6.0",
79 | "jsdom": "^13.0.0",
80 | "nuxt-edge": "^2.3.0-25706271.cca799c",
81 | "standard-version": "^4.4.0",
82 | "webpack-defaults": "^3.0.0"
83 | },
84 | "resolutions": {
85 | "bundle-buddy-webpack-plugin/bundle-buddy": "0.2.1"
86 | },
87 | "husky": {
88 | "hooks": {
89 | "pre-commit": "yarn run lint",
90 | "commit-msg": "yarn run commitlint"
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------