Skip to content

Commit 1ed5d17

Browse files
committed
fix(module/dev): adjust logic after final production tests
1 parent 320b920 commit 1ed5d17

File tree

5 files changed

+159
-126
lines changed

5 files changed

+159
-126
lines changed

README-template.md

+33-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The implementation is based on [laravel-nuxt-js](https://github.com/skyrpex/lara
2222
## Features
2323

2424
* Easyly deploy an existing Nuxt app inside a Laravel application or vice versa
25-
* Test your Nuxt app with live reloading, HMR and the Laravel test server with a single command
25+
* Test your Nuxt app with live reloading, HMR and the autoconfigured Laravel test server
2626
* Seamlessly integrate Nuxt into the URL resolution of Laravel
2727
* Share cookies and session state between frontend (Nuxt) and backend (Laravel) without the need for an API token
2828

@@ -44,9 +44,9 @@ Simply include `nuxt-laravel` in `modules` and set the `mode` setting to `'spa'`
4444
export default {
4545
mode: 'spa',
4646
modules: [
47-
// if you are using @nuxtjs/axios in your config, make sure to include them above nuxt-laravel
48-
//'@nuxtjs/axios',
47+
// Include it first, so that configuration alterations are propagated to other modules
4948
'nuxt-laravel'
49+
// ... other modules
5050
]
5151
}
5252
```
@@ -69,14 +69,13 @@ 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` | `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` |
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+
| `outputPath` | `string` | File location to which an additional index route will be rendered, useful if you want to store it in a folder outside of Laravels public dir (is resolved relative to `root`) | `null` |
77+
| `server` | `boolean` or `object` | Settings for the Laravel testserver | *(see below)* |
78+
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
8079

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

@@ -90,10 +89,10 @@ Setting this to `true` is equivalient to omitting it and will simply use the def
9089
| `host` | `string` | Hostname for the testserver | `nuxtConfig.server.host` |
9190
| `port` | `number` | Port for the testserver | `nuxtConfig.server.port + 1` |
9291

93-
#### The `publicPath` setting
92+
#### Path resolution inside `publicDir`
9493

95-
If `publicPath` is set manually and does not reside inside configured `publicDir` the module will be deactivated.
96-
If `publicPath` is set manually and is valid `nuxtConfig.router.base` will be overwritten with the resolved URL.
94+
If `nuxtConfig.router.base` is not set the SPA will be generated in the `publicDir` root with an index file name of `spa.html`.
95+
If `nuxtConfig.router.base` is set the SPA will be generated in a corresponding location inside `publicDir` with the default index file name `index.html`.
9796

9897
## Laravel integration
9998

@@ -112,14 +111,16 @@ Laravel integration is accomplished through two environment variables.
112111
113112
### Example scaffolding in existent Laravel application
114113

114+
> **Example repo:** [nuxt-laravel-example](https://github.com/m2sd/nuxt-laravel-example)
115+
115116
1. Create a new nuxt app in `resources/nuxt`
116117

117118
```bash
118119
npx create-nuxt-app resources/nuxt
119120
```
120121

121122
2. Migrate all dependencies and scipts (most importantly `dev` and `build`) from `resources/nuxt/package.json` into `package.json` in Laravel root and delete it
122-
3. Move all configuration files from `resources/nuxt` to Laravel root (or merge where appropiate, e.g. `.eslintrc.js`)
123+
3. Move all configuration files from `resources/nuxt` to Laravel root (or merge where appropiate, e.g. `.editorconfig`)
123124
4. Install the module and it's peer dependencies
124125

125126
```bash
@@ -130,9 +131,23 @@ Laravel integration is accomplished through two environment variables.
130131

131132
```js
132133
module.exports = {
134+
srcDir: 'resources/nuxt',
133135
mode: 'spa',
134-
// ...
135-
modules: ['nuxt-laravel']
136+
// ... other config
137+
modules: [
138+
'nuxt-laravel',
139+
// ... other modules
140+
]
141+
}
142+
```
143+
144+
6. (Optional) If you use jest, or other tools that reference the Nuxt root independently, you have to update thier respective configuration to make them work correctly.
145+
Example `jest.config.js`:
146+
147+
```js
148+
module.exports = {
149+
rootDir: 'resources/nuxt',
150+
// ... other configurtion
136151
}
137152
```
138153

@@ -189,7 +204,7 @@ Route::get(
189204

190205
Make sure nuxt path resolution of nuxt router corresponds to the defined routes.
191206

192-
> **IMPORTANT:** This example assumes the module option `publicPath` to have been set to `'app'`.
207+
> **IMPORTANT:** This example assumes option `nuxtConfig.router.base` to have been set to `'/app/'`.
193208
194209
`config/nuxt.php`:
195210

README.md

+33-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The implementation is based on [laravel-nuxt-js](https://github.com/skyrpex/lara
2222
## Features
2323

2424
* Easyly deploy an existing Nuxt app inside a Laravel application or vice versa
25-
* Test your Nuxt app with live reloading, HMR and the Laravel test server with a single command
25+
* Test your Nuxt app with live reloading, HMR and the autoconfigured Laravel test server
2626
* Seamlessly integrate Nuxt into the URL resolution of Laravel
2727
* Share cookies and session state between frontend (Nuxt) and backend (Laravel) without the need for an API token
2828

@@ -44,9 +44,9 @@ Simply include `nuxt-laravel` in `modules` and set the `mode` setting to `'spa'`
4444
export default {
4545
mode: 'spa',
4646
modules: [
47-
// if you are using @nuxtjs/axios in your config, make sure to include them above nuxt-laravel
48-
//'@nuxtjs/axios',
47+
// Include it first, so that configuration alterations are propagated to other modules
4948
'nuxt-laravel'
49+
// ... other modules
5050
]
5151
}
5252
```
@@ -69,14 +69,13 @@ 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` | `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` |
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+
| `outputPath` | `string` | File location to which an additional index route will be rendered, useful if you want to store it in a folder outside of Laravels public dir (is resolved relative to `root`) | `null` |
77+
| `server` | `boolean` or `object` | Settings for the Laravel testserver | *(see below)* |
78+
| `dotEnvExport` | `boolean` | Whether the `NUXT_OUTPUT_PATH` varibale should be written to the `.env` file in the laravel root directory | `false` |
8079

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

@@ -90,10 +89,10 @@ Setting this to `true` is equivalient to omitting it and will simply use the def
9089
| `host` | `string` | Hostname for the testserver | `nuxtConfig.server.host` |
9190
| `port` | `number` | Port for the testserver | `nuxtConfig.server.port + 1` |
9291

93-
#### The `publicPath` setting
92+
#### Path resolution inside `publicDir`
9493

95-
If `publicPath` is set manually and does not reside inside configured `publicDir` the module will be deactivated.
96-
If `publicPath` is set manually and is valid `nuxtConfig.router.base` will be overwritten with the resolved URL.
94+
If `nuxtConfig.router.base` is not set the SPA will be generated in the `publicDir` root with an index file name of `spa.html`.
95+
If `nuxtConfig.router.base` is set the SPA will be generated in a corresponding location inside `publicDir` with the default index file name `index.html`.
9796

9897
## Laravel integration
9998

@@ -112,14 +111,16 @@ Laravel integration is accomplished through two environment variables.
112111
113112
### Example scaffolding in existent Laravel application
114113

114+
> **Example repo:** [nuxt-laravel-example](https://github.com/m2sd/nuxt-laravel-example)
115+
115116
1. Create a new nuxt app in `resources/nuxt`
116117

117118
```bash
118119
npx create-nuxt-app resources/nuxt
119120
```
120121

121122
2. Migrate all dependencies and scipts (most importantly `dev` and `build`) from `resources/nuxt/package.json` into `package.json` in Laravel root and delete it
122-
3. Move all configuration files from `resources/nuxt` to Laravel root (or merge where appropiate, e.g. `.eslintrc.js`)
123+
3. Move all configuration files from `resources/nuxt` to Laravel root (or merge where appropiate, e.g. `.editorconfig`)
123124
4. Install the module and it's peer dependencies
124125

125126
```bash
@@ -130,9 +131,23 @@ Laravel integration is accomplished through two environment variables.
130131

131132
```js
132133
module.exports = {
134+
srcDir: 'resources/nuxt',
133135
mode: 'spa',
134-
// ...
135-
modules: ['nuxt-laravel']
136+
// ... other config
137+
modules: [
138+
'nuxt-laravel',
139+
// ... other modules
140+
]
141+
}
142+
```
143+
144+
6. (Optional) If you use jest, or other tools that reference the Nuxt root independently, you have to update thier respective configuration to make them work correctly.
145+
Example `jest.config.js`:
146+
147+
```js
148+
module.exports = {
149+
rootDir: 'resources/nuxt',
150+
// ... other configurtion
136151
}
137152
```
138153

@@ -189,7 +204,7 @@ Route::get(
189204

190205
Make sure nuxt path resolution of nuxt router corresponds to the defined routes.
191206

192-
> **IMPORTANT:** This example assumes the module option `publicPath` to have been set to `'app'`.
207+
> **IMPORTANT:** This example assumes option `nuxtConfig.router.base` to have been set to `'/app/'`.
193208
194209
`config/nuxt.php`:
195210

0 commit comments

Comments
 (0)