Skip to content

feat: support overwriting components#96

Merged
pi0 merged 6 commits intomasterfrom
feat/component-overwrite
Nov 23, 2020
Merged

feat: support overwriting components#96
pi0 merged 6 commits intomasterfrom
feat/component-overwrite

Conversation

@atinux
Copy link
Copy Markdown
Member

@atinux atinux commented Oct 8, 2020

The idea came to allow user to overwrites components in the Nuxt Docs Theme: nuxt/content#542

With this PR, we can now have:

node_modules/
  my-theme/
    components/
      Header.vue
components/
   Header.vue

Then defining in the nuxt.config:

export default {
  components: [
    '~/components', // default level is 0
   { path: 'node_modules/my-theme/components', level: 1 }
  ]
}

Our components/Header.vue will overwrites our theme component if defined since the lowest level overwrites.

@atinux atinux requested review from kevinmarrec and pi0 October 8, 2020 12:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 8, 2020

Codecov Report

Merging #96 (c71468c) into master (021c4ea) will increase coverage by 1.62%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
+ Coverage   96.22%   97.84%   +1.62%     
==========================================
  Files           7       14       +7     
  Lines         159      372     +213     
  Branches       40       77      +37     
==========================================
+ Hits          153      364     +211     
- Misses          6        8       +2     
Impacted Files Coverage Δ
test/fixture/nuxt.config.ts 100.00% <ø> (+75.00%) ⬆️
src/scan.ts 100.00% <100.00%> (+2.12%) ⬆️
src/index.ts 95.38% <0.00%> (-2.95%) ⬇️
test/unit/utils.ts 100.00% <0.00%> (ø)
src/tagExtractor.ts 100.00% <0.00%> (ø)
src/compatibility.ts 100.00% <0.00%> (ø)
D:/a/components/components/src/scan.ts 100.00% <0.00%> (ø)
D:/a/components/components/src/loader.ts 96.15% <0.00%> (ø)
D:/a/components/components/test/unit/utils.ts 100.00% <0.00%> (ø)
.../components/components/test/fixture/nuxt.config.ts 100.00% <0.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 021c4ea...257b429. Read the comment docs.

@pi0
Copy link
Copy Markdown
Member

pi0 commented Oct 8, 2020

Nice idea! But without #81 (full prefix) this is a breaking change since we change behavior by using component from longest path to component with shortest path (actually i think we can have same behavior by changing sort)

@kevinmarrec
Copy link
Copy Markdown
Contributor

kevinmarrec commented Oct 8, 2020

Agreed with @pi0 comment.

Something we can do is integrating #81 (full prefix) as default for 2.x with an opt-out flag, and eventually making it opt-in for 1.x first as suggested by @pi0 in the full prefix PR.

We will probably need 2 behaviors concerning this PR (overwriting components) too, depending if full prefix is enabled or not, so it works in both case, OR only have this feature working with full prefix enabled.

EDIT : Btw cool feature @atinux :) !

@pperzyna
Copy link
Copy Markdown

pperzyna commented Nov 1, 2020

I would love to have it. It is crucial for building bigger apps.

Is there any workaround for now? How to override components or specific that eg for this folder components have higher priority?

@atinux
Copy link
Copy Markdown
Member Author

atinux commented Nov 2, 2020

@pperzyna we need to release a new version of @nuxt/components before being able to merge this ;)

@pi0 pi0 merged commit 47a21e9 into master Nov 23, 2020
@pi0 pi0 deleted the feat/component-overwrite branch November 23, 2020 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants