Comments (2)
Start a new pull request in StackBlitz Codeflow.
from nuxt.js.
I've done a bit of research here...
So. When there are layers, nuxt._layers becomes an array of the root project, followed by the layers. This can be demonstrated with:
hooks: {
ready(nuxt) {
console.log('ready: ', nuxt.options._layers);
},
So the first layer is the root, the second layer is an actual layer.
Then when nuxt creates nitro, it uses these layers in the nitro scanDirs
options:
https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L96
The scanDirs
in this object are passed into a call to createNitro()
here:
https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L397
At that point they look like this:
[
'/home/projects/nuxt-framework-cecwxh/server', // root "layer"
'/home/projects/nuxt-framework-cecwxh/layer/server' // other layers
]
Which can be seen by:
hooks: {
'nitro:config'(config) {
console.log(config.scanDirs);
}
}
These scanDirs get looped over and a /utils/*
appended to them here:
https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts#L30
Then they get passed in as imports.dirs to unImport here:
https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/paths.ts#L67
unImport does priority by order of dirs with the last dir in the array taking more priority - ref:
unjs/unimport#141
I tried to reverse the order of the scan imports by doing:
hooks: {
'nitro:config'(config) {
console.log('scanDirs before nitro init', config.scanDirs);
config.scanDirs?.reverse();
},
}
However... This doesn't work because the root dir gets unshifted onto the array by nitro anyway and then deduped so it ends up at the start of the array again...
createNitro
calls loadOptions()
here:
https://github.com/unjs/nitro/blob/v2/src/core/nitro.ts#L24
loadOptions
loops over the configResolvers
can calls them which includes resolvePathOptions
here:
https://github.com/unjs/nitro/blob/v2/src/core/config/loader.ts#L32
resolvePathOptions
does an unshift()
on scanDirs
to add the root to the start of the array here:
https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/paths.ts#L67
There is no hook between this happening, and nitro calling unImport.init() so you can never end up with the root project imports being after the layer imports, and because of the priority of unImport, that means that the layer imports always override the root project imports.
I'm not sure what the fix for this should be, potentially change the unshift to a push() in nitro? And then reverse the order of _layers in nuxt? Tricky one... But I'm happy to make a PR (or two) with some guidance @danielroe @pi0 ?
from nuxt.js.
Related Issues (20)
- Server side useCookie problem HOT 1
- Potential Memory Leak HOT 4
- dynamic route is not found ! HOT 2
- Nuxt Plugin "provide" is not typed automatically since v3.13.0 HOT 7
- future: { compatibilityVersion: 4 } Messes up some types HOT 2
- serverDir not being registered HOT 3
- Client chunk too large with experimental.componentIslands.selectiveClient (to true) and @nuxt/client HOT 1
- runtime config in `.env` is not loaded in production HOT 2
- Error parsing JavaScript expression: Expecting Unicode escape sequence \uXXXX HOT 4
- Make server routes aware of page routes to avoid collisions HOT 1
- Nuxt middleware performs undefined behaviour when protecting routes HOT 4
- Property X does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>> HOT 5
- `useRoute.matched` is not returning all matching routes HOT 4
- More visible error messages when getting restricted due to import protection
- free(): invalid size and socket hang up HOT 4
- local postcss plugin error HOT 1
- ENOENT: no such file or directory, access '/tmp/nitro/worker-*.*.sock' HOT 2
- Vite SASS modern compiler causes missing sourcefiles issue HOT 1
- Change meta.pageTransition via global middleware doesn't work
- Error: locale postcss plugin HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.