Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fumeapp/nuxt-storm
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 16, 2021
2 parents d8d60ca + c5190dc commit 1f8697e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
7 changes: 6 additions & 1 deletion dist/module.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default function stormModule(moduleOptions: any): void;
interface Options {
nested?: boolean;
alias?: string | boolean;
}
export default function stormModule(moduleOptions: Options): void;
export {};
14 changes: 13 additions & 1 deletion dist/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ export default function stormModule(moduleOptions) {
this.nuxt.hook('components:extend', dirs => {
components = [...dirs].map(file => {
count++;
return { name: file.pascalName, file: file.filePath };
let filePath;
if (moduleOptions.alias) {
let alias;
if (typeof moduleOptions.alias !== 'string')
alias = '@';
else
alias = moduleOptions.alias;
filePath = `${alias}/${file.filePath.slice(file.filePath.indexOf('components'))}`;
}
else {
filePath = file.filePath;
}
return { name: file.pascalName, file: filePath };
});
if (moduleOptions.nested) {
logger.info(`Nested components option detected`);
Expand Down
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ The component name will contain its path:
<MyFormTextArea />
```

### Path alias

Should your IDE fail to recognize vue component by its absolute path, you can replace it with path alias (default '@').

Thus, the aforementioned component path will be listed as
`@/components/My/Form/TextArea.vue`
instead of
`C:/some/absolute/path/project/components/My/Form/TextArea.vue`.

Add `alias: true` in your buildModule inclusion or set a custom alias as its value should you use one.

```js
{
buildModules: [
['nuxt-storm', { alias: true }],
]
}
```

### 🙏 Thanks

This was made possible by with the help of [grunghi](https://github.com/grunghi) and [eggsy](https://github.com/eggsy/)
Expand Down
17 changes: 15 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { resolve } from 'path'
import consola from 'consola'

export default function stormModule (moduleOptions) {
interface Options {
nested?: boolean
alias?: string | boolean
}

export default function stormModule (moduleOptions: Options) {
if (process.env.NODE_ENV === 'production') {
return
}
Expand All @@ -12,7 +17,15 @@ export default function stormModule (moduleOptions) {
this.nuxt.hook('components:extend', dirs => {
components = [...dirs].map(file => {
count++
return { name: file.pascalName, file: file.filePath}
let filePath
if (moduleOptions.alias) {
let alias
if (typeof moduleOptions.alias !== 'string') alias = '@'
else alias = moduleOptions.alias
filePath = `${alias}/${file.filePath.slice(file.filePath.indexOf('components'))}`
}
else { filePath = file.filePath }
return { name: file.pascalName, file: filePath}
})

if (moduleOptions.nested) {
Expand Down
4 changes: 3 additions & 1 deletion templates/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import Vue from 'vue'
}).join('\n') %>

<%= options.getComponents().map(({ name, file }) => {
return `Vue.component('${name}', ${name})`
let template = `Vue.component('${name}', ${name})`
template += `\nVue.component('Lazy${name}', ${name})`
return template
}).join('\n') %>

0 comments on commit 1f8697e

Please sign in to comment.