nuxt-loaders 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Haileab Tesfaye
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.
package/README.md CHANGED
@@ -2,83 +2,123 @@
2
2
  Get your module up and running quickly.
3
3
 
4
4
  Find and replace all on all files (CMD+SHIFT+F):
5
- - Name: My Module
6
- - Package name: my-module
7
- - Description: My new Nuxt module
5
+ - Name: Nuxt Loaders
6
+ - Package name: nuxt-loaders
7
+ - Description: Simple loading screen engine for Nuxt 4+
8
8
  -->
9
9
 
10
- # My Module
10
+ # Nuxt Loaders
11
11
 
12
12
  [![npm version][npm-version-src]][npm-version-href]
13
13
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
14
14
  [![License][license-src]][license-href]
15
15
  [![Nuxt][nuxt-src]][nuxt-href]
16
16
 
17
- My new Nuxt module for doing amazing things.
17
+ Simple loading screen engine for Nuxt 4+.
18
18
 
19
19
  - [✨  Release Notes](/CHANGELOG.md)
20
- <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
21
- <!-- - [📖 &nbsp;Documentation](https://example.com) -->
20
+ <!-- - [🏀 Online playground](https://stackblitz.com/github/haileabt/nuxt-loaders?file=playground%2Fapp.vue) -->
21
+ <!-- - [📖 &nbsp;Documentation](https://example.com) -->
22
22
 
23
23
  ## Features
24
24
 
25
- <!-- Highlight some of the features your module provide here -->
26
- - &nbsp;Foo
27
- - 🚠 &nbsp;Bar
28
- - 🌲 &nbsp;Baz
25
+ - 🔄 **Automatic Loader Registration**: Automatically registers loader components from your specified directory.
26
+ - 🛣️ **Route-based Configuration**: Assign specific loaders to different routes using `routeRules`.
27
+ - 🎨 **TailwindCSS Integration**: Includes TailwindCSS support out of the box.
28
+ - **Zero Configuration**: Works with sensible defaults, but fully customizable.
29
29
 
30
30
  ## Quick Setup
31
31
 
32
- Install the module to your Nuxt application with one command:
32
+ 1. Add `nuxt-loaders` dependency to your project
33
33
 
34
34
  ```bash
35
- npx nuxi module add my-module
35
+ npx nuxi module add nuxt-loaders
36
36
  ```
37
37
 
38
- That's it! You can now use My Module in your Nuxt app ✨
38
+ 2. Add `nuxt-loaders` to the `modules` section of `nuxt.config.ts`
39
39
 
40
+ ```ts
41
+ export default defineNuxtConfig({
42
+ modules: ["nuxt-loaders"],
43
+ });
44
+ ```
40
45
 
41
- ## Contribution
46
+ That's it! You can now use Nuxt Loaders in your Nuxt app ✨
42
47
 
43
- <details>
44
- <summary>Local development</summary>
45
-
46
- ```bash
47
- # Install dependencies
48
- npm install
49
-
50
- # Generate type stubs
51
- npm run dev:prepare
52
-
53
- # Develop with the playground
54
- npm run dev
55
-
56
- # Build the playground
57
- npm run dev:build
58
-
59
- # Run ESLint
60
- npm run lint
61
-
62
- # Run Vitest
63
- npm run test
64
- npm run test:watch
65
-
66
- # Release new version
67
- npm run release
68
- ```
69
-
70
- </details>
48
+ ## Configuration
71
49
 
50
+ You can configure the module in your `nuxt.config.ts`:
72
51
 
73
- <!-- Badges -->
74
- [npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
75
- [npm-version-href]: https://npmjs.com/package/my-module
52
+ ```ts
53
+ export default defineNuxtConfig({
54
+ modules: ["nuxt-loaders"],
55
+ loaders: {
56
+ // Directory containing your loader components
57
+ // Default: 'app/components/loaders'
58
+ loadersDir: "app/components/loaders",
59
+
60
+ // Automatically setup the module
61
+ // Default: true
62
+ autoSetup: true,
63
+
64
+ // Define rules for which loader to use on which route
65
+ routeRules: {
66
+ "/": "MyLoader",
67
+ "/admin/*": "AdminLoader",
68
+ },
69
+ },
70
+ });
71
+ ```
72
+
73
+ ### Options
74
+
75
+ | Option | Type | Default | Description |
76
+ | ------------ | ------------------------ | -------------------------- | --------------------------------------------------- |
77
+ | `loadersDir` | `string` | `'app/components/loaders'` | Directory where your loader components are located. |
78
+ | `autoSetup` | `boolean` | `true` | Whether to automatically setup the module. |
79
+ | `routeRules` | `Record<string, string>` | `{}` | Map of route patterns to loader component names. |
80
+
81
+ ## Usage
82
+
83
+ 1. **Add the Loader Component**:
84
+ Add the `<Loader />` component to your `app.vue` (or layout) and control its visibility using `useLoader`.
76
85
 
77
- [npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
78
- [npm-downloads-href]: https://npm.chart.dev/my-module
86
+ ```vue
87
+ <script setup lang="ts">
88
+ const { isLoading } = useLoader();
89
+ </script>
79
90
 
80
- [license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
81
- [license-href]: https://npmjs.com/package/my-module
91
+ <template>
92
+ <Loader v-if="isLoading" />
93
+ <NuxtPage />
94
+ </template>
95
+ ```
96
+
97
+ 2. **Create your loader components**:
98
+ Place them in `app/components/loaders` (or your configured `loadersDir`).
99
+
100
+ 3. **Configure Route Rules**:
101
+ Use `routeRules` in your `nuxt.config.ts` to specify which loader should be active for specific routes.
102
+
103
+ Example loader component (`app/components/loaders/MyLoader.vue`):
104
+
105
+ ```vue
106
+ <template>
107
+ <div class="loader">Loading...</div>
108
+ </template>
109
+ ```
110
+
111
+ ## Contribution
112
+
113
+ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
114
+
115
+ <!-- Badges -->
82
116
 
117
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-loaders/latest.svg?style=flat&colorA=020420&colorB=00DC82
118
+ [npm-version-href]: https://npmjs.com/package/nuxt-loaders
119
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-loaders.svg?style=flat&colorA=020420&colorB=00DC82
120
+ [npm-downloads-href]: https://npm.chart.dev/nuxt-loaders
121
+ [license-src]: https://img.shields.io/npm/l/nuxt-loaders.svg?style=flat&colorA=020420&colorB=00DC82
122
+ [license-href]: https://npmjs.com/package/nuxt-loaders
83
123
  [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
84
124
  [nuxt-href]: https://nuxt.com
package/dist/module.d.mts CHANGED
@@ -4,6 +4,7 @@ interface ModuleOptions {
4
4
  autoSetup: boolean;
5
5
  loadersDir?: string;
6
6
  routeRules: Record<string, string>;
7
+ disableDefault: boolean;
7
8
  _activeLoader: string;
8
9
  _defaultLoader: string;
9
10
  }
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-loaders",
3
3
  "configKey": "loaders",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -14,7 +14,7 @@ const module$1 = defineNuxtModule({
14
14
  defaults: {
15
15
  autoSetup: true,
16
16
  routeRules: {},
17
- _defaultLoader: "",
17
+ _defaultLoader: "DefaultLoader",
18
18
  _activeLoader: ""
19
19
  },
20
20
  async setup(options, nuxt) {
@@ -74,7 +74,7 @@ export default defineNuxtPlugin((nuxtApp) => {
74
74
  if (options.routeRules && Object.keys(options.routeRules).length > 0) {
75
75
  nuxt.options.runtimeConfig.public.loaders._activeLoader = getDefaultLoader(validatedLoaderRules) ?? "";
76
76
  }
77
- nuxt.options.runtimeConfig.public.loaders._defaultLoader = getDefaultLoader(validatedLoaderRules) ?? "";
77
+ nuxt.options.runtimeConfig.public.loaders._defaultLoader = getDefaultLoader(validatedLoaderRules) ?? "DefaultLoader";
78
78
  addPlugin(resolver.resolve("./runtime/plugin"));
79
79
  }
80
80
  });
@@ -0,0 +1,8 @@
1
+ type __VLS_Props = {
2
+ className?: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
5
+ className: string;
6
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <div :class="['loader', className]">
3
+ <h1>Loading{{ dots }}</h1>
4
+ </div>
5
+ </template>
6
+
7
+ <script setup>
8
+ import { onMounted, onUnmounted, ref } from "vue";
9
+ const dots = ref(".");
10
+ let interval;
11
+ onMounted(() => {
12
+ interval = setInterval(() => {
13
+ dots.value = dots.value.length >= 3 ? "." : dots.value + ".";
14
+ }, 500);
15
+ });
16
+ onUnmounted(() => clearInterval(interval));
17
+ defineProps({
18
+ className: { type: String, required: false, default: "" }
19
+ });
20
+ </script>
@@ -0,0 +1,8 @@
1
+ type __VLS_Props = {
2
+ className?: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
5
+ className: string;
6
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -1,3 +1,8 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ className?: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
5
+ className: string;
6
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
7
  declare const _default: typeof __VLS_export;
3
8
  export default _default;
@@ -1,6 +1,6 @@
1
1
  <template>
2
- <div>
3
- <component :is="loaderName" v-if="loaderName" />
2
+ <div :class="[className, 'w-[100vw] h-[100svh] absolute top-0 left-0 z-50 grid place-items-center bg-white']">
3
+ <component :is="loaderName" />
4
4
  </div>
5
5
  </template>
6
6
 
@@ -17,4 +17,7 @@ const loaderName = computed(() => {
17
17
  }
18
18
  return name;
19
19
  });
20
+ defineProps({
21
+ className: { type: String, required: false, default: "" }
22
+ });
20
23
  </script>
@@ -1,3 +1,8 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ className?: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
5
+ className: string;
6
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
7
  declare const _default: typeof __VLS_export;
3
8
  export default _default;
@@ -1,3 +1,3 @@
1
1
  export declare const validateLoaderRules: (routeRules: Record<string, string>) => Record<string, string>;
2
- export declare const getDefaultLoader: (routeRules: Record<string, string>) => string | undefined;
2
+ export declare const getDefaultLoader: (routeRules: Record<string, string>, defaultLoaderName?: string) => string | undefined;
3
3
  export declare const getActiveLoader: (routeRules: Record<string, string>, path: string) => string | undefined;
@@ -13,11 +13,11 @@ const checkRoutePatternValidity = (route) => {
13
13
  if (route === "*" || route === "/") {
14
14
  return { valid: true };
15
15
  }
16
- const routePattern = /^\/[\w\-/]*$/;
16
+ const routePattern = /^\/[\w\-/]*(?:\/\*)?$/;
17
17
  if (!routePattern.test(route)) {
18
18
  return {
19
19
  valid: false,
20
- reason: "Route pattern is invalid. Must start with '/' and contain only alphanumeric characters, hyphens, underscores, or slashes."
20
+ reason: "Route pattern is invalid. Must start with '/' and contain only alphanumeric characters, hyphens, underscores, astrix or slashes."
21
21
  };
22
22
  }
23
23
  return { valid: true };
@@ -62,22 +62,28 @@ export const validateLoaderRules = (routeRules) => {
62
62
  });
63
63
  return newRules;
64
64
  };
65
- export const getDefaultLoader = (routeRules) => {
65
+ export const getDefaultLoader = (routeRules, defaultLoaderName = "DefaultLoader") => {
66
66
  const defaultLoader = Object.keys(routeRules).filter((key) => {
67
67
  return key === "*" || key === "/";
68
68
  });
69
69
  if (defaultLoader.length <= 0) {
70
- return "";
70
+ return defaultLoaderName;
71
71
  }
72
72
  if (defaultLoader.length > 1) {
73
73
  return routeRules["*"];
74
74
  }
75
- return routeRules[defaultLoader[0]];
75
+ return routeRules[defaultLoader[0]] || defaultLoaderName;
76
76
  };
77
77
  export const getActiveLoader = (routeRules, path) => {
78
+ if (path.endsWith("/")) {
79
+ path = path.substring(0, -1);
80
+ }
78
81
  const rules = Object.keys(routeRules).filter((rule2) => {
82
+ if (rule2.endsWith("/")) {
83
+ rule2 = rule2.substring(0, -1);
84
+ }
79
85
  if (!path.startsWith(rule2)) return false;
80
- if (!path.endsWith("*") && path != rule2) return false;
86
+ if (!rule2.endsWith("/*") && path != rule2) return false;
81
87
  return true;
82
88
  });
83
89
  if (rules.length <= 0) {
@@ -1 +1 @@
1
- @import "tailwindcss";
1
+ @import "tailwindcss";@source "./**/*.{vue,js,ts,html}";@source "../components/**/*.{vue,js,ts}";@source "../pages/**/*.{vue,js,ts}";@source "../layouts/**/*.{vue,js,ts}";
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "nuxt-loaders",
3
- "version": "1.0.0",
4
- "description": "My new Nuxt module",
5
- "repository": "your-org/my-module",
3
+ "version": "1.1.0",
4
+ "description": "Simple loading screen engine for Nuxt 4+",
5
+ "repository": "haileabt/nuxt-loaders",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "exports": {