Skip to content

Commit e445e0a

Browse files
committed
fix(server): support boolean settings
1 parent 967d1f5 commit e445e0a

File tree

5 files changed

+50
-34
lines changed

5 files changed

+50
-34
lines changed

README-template.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,22 @@ export default {
6969

7070
### Module Options
7171

72-
| option | type | description | default |
73-
| -------------- | --------- | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
74-
| `root` | `string` | Path to laravel directory (is resolved relative to `process.cwd()`) | `process.cwd()` |
75-
| `publicDir` | `string` | The folder where laravel serves assets from (is resolved relative to `root`) | `'public'` |
76-
| `publicPath` | `string` | Folder location to which generated assets are output (is resolved relative to and must reside in `publicDir`) | `process.env.NUXT_OUTPUT_PATH || nuxtConfig.router.base` |
77-
| `outputPath` | `string` | File location to which the index route will be rendered, (is resolved relative to `root`) | `path.join(publicDir, publicPath, '_spa.html')` |
78-
| `server` | `object` | Settings for the Laravel testserver | *(see below)* |
79-
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
72+
| option | type | description | default |
73+
| -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
74+
| `root` | `string` | Path to laravel directory (is resolved relative to `process.cwd()`) | `process.cwd()` |
75+
| `publicDir` | `string` | The folder where laravel serves assets from (is resolved relative to `root`) | `'public'` |
76+
| `publicPath` | `string` | Folder location to which generated assets are output (is resolved relative to and must reside in `publicDir`) | `process.env.NUXT_OUTPUT_PATH \|\| nuxtConfig.router.base` |
77+
| `outputPath` | `string` | File location to which the index route will be rendered, (is resolved relative to `root`) | `path.join(publicDir, publicPath, '_spa.html')` |
78+
| `server` | `boolean` or `object` | Settings for the Laravel testserver | *(see below)* |
79+
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
8080

8181
The module loads the `.env` file from yout laravel root, so you can set the `NUXT_OUTPUT_PATH` environment variable from there.
8282

8383
#### The `server` setting
8484

85+
If this setting is set to `false` the module will be disabled for development.
86+
Setting this to `true` is equivalient to omitting it and will simply use the default configuration.
87+
8588
| option | type | description | default |
8689
| ------ | -------- | --------------------------- | ---------------------------- |
8790
| `host` | `string` | Hostname for the testserver | `nuxtConfig.server.host` |

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,22 @@ export default {
6969

7070
### Module Options
7171

72-
| option | type | description | default |
73-
| -------------- | --------- | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
74-
| `root` | `string` | Path to laravel directory (is resolved relative to `process.cwd()`) | `process.cwd()` |
75-
| `publicDir` | `string` | The folder where laravel serves assets from (is resolved relative to `root`) | `'public'` |
76-
| `publicPath` | `string` | Folder location to which generated assets are output (is resolved relative to and must reside in `publicDir`) | `process.env.NUXT_OUTPUT_PATH || nuxtConfig.router.base` |
77-
| `outputPath` | `string` | File location to which the index route will be rendered, (is resolved relative to `root`) | `path.join(publicDir, publicPath, '_spa.html')` |
78-
| `server` | `object` | Settings for the Laravel testserver | *(see below)* |
79-
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
72+
| option | type | description | default |
73+
| -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
74+
| `root` | `string` | Path to laravel directory (is resolved relative to `process.cwd()`) | `process.cwd()` |
75+
| `publicDir` | `string` | The folder where laravel serves assets from (is resolved relative to `root`) | `'public'` |
76+
| `publicPath` | `string` | Folder location to which generated assets are output (is resolved relative to and must reside in `publicDir`) | `process.env.NUXT_OUTPUT_PATH \|\| nuxtConfig.router.base` |
77+
| `outputPath` | `string` | File location to which the index route will be rendered, (is resolved relative to `root`) | `path.join(publicDir, publicPath, '_spa.html')` |
78+
| `server` | `boolean` or `object` | Settings for the Laravel testserver | *(see below)* |
79+
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
8080

8181
The module loads the `.env` file from yout laravel root, so you can set the `NUXT_OUTPUT_PATH` environment variable from there.
8282

8383
#### The `server` setting
8484

85+
If this setting is set to `false` the module will be disabled for development.
86+
Setting this to `true` is equivalient to omitting it and will simply use the default configuration.
87+
8588
| option | type | description | default |
8689
| ------ | -------- | --------------------------- | ---------------------------- |
8790
| `host` | `string` | Hostname for the testserver | `nuxtConfig.server.host` |

lib/module.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ const laravelModule = function (_moduleOptions) {
2626
publicDir: 'public',
2727
publicPath: baseUrl,
2828
outputPath: path_1.default.join(process.cwd(), 'public', baseUrl, '_spa.html'),
29-
server: this.options.dev && this.options.server
30-
? {
31-
host: this.options.server.host,
32-
port: +(this.options.server.port || 3000) + 1
33-
}
34-
: false,
29+
server: true,
3530
dotEnvExport: false
3631
}, this.options.laravel, _moduleOptions);
32+
if (typeof moduleOptions.server === 'boolean' && moduleOptions.server) {
33+
moduleOptions.server =
34+
this.options.dev && this.options.server
35+
? {
36+
host: this.options.server.host,
37+
port: +(this.options.server.port || 3000) + 1
38+
}
39+
: false;
40+
}
3741
const laravelRoot = path_1.default.resolve(process.cwd(), moduleOptions.root);
3842
const generateDir = path_1.default.join(laravelRoot, moduleKey);
3943
const publicDir = path_1.default.resolve(laravelRoot, moduleOptions.publicDir);

src/module.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ export interface Options {
1616
publicDir?: string
1717
publicPath?: string
1818
outputPath?: string
19-
server?: {
20-
host?: string
21-
port?: number
22-
}
19+
server?:
20+
| boolean
21+
| {
22+
host?: string
23+
port?: number
24+
}
2325
dotEnvExport?: boolean
2426
}
2527

@@ -42,18 +44,22 @@ const laravelModule: Module<Options> = function(_moduleOptions) {
4244
publicDir: 'public',
4345
publicPath: baseUrl,
4446
outputPath: path.join(process.cwd(), 'public', baseUrl, '_spa.html'),
45-
server:
46-
this.options.dev && this.options.server
47-
? {
48-
host: this.options.server.host,
49-
port: +(this.options.server.port || 3000) + 1
50-
}
51-
: false,
47+
server: true,
5248
dotEnvExport: false
5349
},
5450
this.options.laravel,
5551
_moduleOptions
5652
)
53+
54+
if (typeof moduleOptions.server === 'boolean' && moduleOptions.server) {
55+
moduleOptions.server =
56+
this.options.dev && this.options.server
57+
? {
58+
host: this.options.server.host,
59+
port: +(this.options.server.port || 3000) + 1
60+
}
61+
: false
62+
}
5763
const laravelRoot = path.resolve(process.cwd(), moduleOptions.root)
5864
const generateDir = path.join(laravelRoot, moduleKey)
5965
const publicDir = path.resolve(laravelRoot, moduleOptions.publicDir)

types/module.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Options {
44
publicDir?: string;
55
publicPath?: string;
66
outputPath?: string;
7-
server?: {
7+
server?: boolean | {
88
host?: string;
99
port?: number;
1010
};

0 commit comments

Comments
 (0)