@aceforth/nuxt-netlify 中文文档教程
Nuxt Netlify
在您的 Nuxt.js 项目中为 Netlify 动态生成 _headers
和 _redirects
文件。
此模块支持创建redirects 和 header 规则为您的 Netlify 站点:您可以轻松配置自定义标头、基本身份验证、重定向指令和重写规则从你的 nuxt 配置文件。
Installation
:警告:< code>node >= 10 和 nuxt >= 2
是必需的。
```狂欢 npm install --save-dev @aceforth/nuxt-netlify
or
bash 纱线添加--dev @aceforth/nuxt-netlify
Add `@aceforth/nuxt-netlify` to the `buildModules` section of `nuxt.config.js`:
:warning: If you are using Nuxt `< 2.9.0`, use `modules` instead.
js { 构建模块:[ '@aceforth/nuxt-netlify', ],
网络化: { mergeSecurityHeaders:真 } }
or
_ { 构建模块:[ [ '@aceforth/nuxt-netlify', { mergeSecurityHeaders:真 } ] ] }
## Usage
The default configuration will generate an empty `_redirects` file and a `_headers` file with some caching and security headers:
文本
_headers
/* 推荐人政策:起源 X 内容类型选项:nosniff X 框架选项:拒绝 X-XSS-保护:1; 模式=块
/_nuxt/* 缓存控制:public,max-age=31536000,不可变
/sw.js 缓存控制:无缓存
> :warning: the `/_nuxt/*` reference automatically changes with the value of [`build.publicPath`][nuxt-docs-build-publicPath].
### Headers
The headers object represents a JS version of the [Netlify `_headers` file format][netlify-headers-and-basic-auth]. You should pass in a object with string keys (representing the paths) and an array of strings for each header. For example:
You can add extra headers as follows:
js const pkg = require('./package.json')
{ 网络化:{ 标题:{ '/*':[ '访问控制允许来源:*', X-Build:${pkg.version}
], '/favicon.ico':[ '缓存控制:公共,最大年龄= 86400' ] } } }
that will generate:
文本
_headers
/* 推荐人政策:起源 X 内容类型选项:nosniff X 框架选项:拒绝 X-XSS-保护:1; 模式=块 访问控制允许来源:* X-构建:1.0.1
/_nuxt/* 缓存控制:public,max-age=31536000,不可变
/sw.js 缓存控制:无缓存
/favicon.ico 缓存控制:public,max-age=86400
### Redirects
You can also add [redirects][netlify-redirects], as many as you like. You should pass in an array of objects with the redirection attributes. For example:
js { 网络化:{ 重定向:[ { 从家里', 到: '/' }, { 来自:'/我的重定向', 到: '/', 状态:302, 力量:真实 }, { 来自:'/en/', 到:'/en/404.html', 状态:404 }, { 来自: '/', 到:'/index.html', 状态:200 }, { 来自:'/商店', 到:'/博客/:id', 询问: { 编号:':编号' } }, { 从: '/', 至:'/中国', 状态:302, 状况: { 国家:'cn,hk,tw' } } ] } }
will generate:
文本
_redirects
/家/ 301 /我的重定向/ 302! /zh/* /zh/404.html 404 /* /index.html 200 /store id=:id /博客/:id 301 //china 302 国家=cn,hk,tw ```
查看所有的配置部分可用选项。
Documentation & Support
- If you want extra details of how to configure and use this project, the full documentation is available at https://marquez.co/docs/nuxt-netlify/.
- For Bug reports or Feature requests, use the Issues section.
- For questions, you can also use the Issues section.
- You may also want to follow me on Twitter.
Professional Support
这个项目是由我这个全栈开发人员发起的。 如果您的项目需要专业协助,请通过 https://marquez 与我联系。合作。
Code of Conduct
参与此项目的每个人都应同意遵守行为准则。
License
代码根据 MIT 许可 发布。
[nuxt-docs-build-publicPath]: https:// nuxtjs.org/api/configuration-build#publicPath
Nuxt Netlify
Dynamically generate _headers
and _redirects
files for Netlify in your Nuxt.js projects.
This module supports the creation of redirects and header rules for your Netlify site: you can easily configure custom headers, basic auth, redirect instructions and rewrite rules from your nuxt config file.
Read this in other languages: English, Español
Installation
:warning: node >= 10
and nuxt >= 2
are required.
```bash npm install --save-dev @aceforth/nuxt-netlify
or
bash yarn add --dev @aceforth/nuxt-netlify
Add `@aceforth/nuxt-netlify` to the `buildModules` section of `nuxt.config.js`:
:warning: If you are using Nuxt `< 2.9.0`, use `modules` instead.
js { buildModules: [ '@aceforth/nuxt-netlify', ],
netlify: { mergeSecurityHeaders: true } }
or
js { buildModules: [ [ '@aceforth/nuxt-netlify', { mergeSecurityHeaders: true } ] ] }
## Usage
The default configuration will generate an empty `_redirects` file and a `_headers` file with some caching and security headers:
text
_headers
/* Referrer-Policy: origin X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; mode=block
/_nuxt/* Cache-Control: public, max-age=31536000, immutable
/sw.js Cache-Control: no-cache
> :warning: the `/_nuxt/*` reference automatically changes with the value of [`build.publicPath`][nuxt-docs-build-publicPath].
### Headers
The headers object represents a JS version of the [Netlify `_headers` file format][netlify-headers-and-basic-auth]. You should pass in a object with string keys (representing the paths) and an array of strings for each header. For example:
You can add extra headers as follows:
js const pkg = require('./package.json')
{ netlify: { headers: { '/*': [ 'Access-Control-Allow-Origin: *', X-Build: ${pkg.version}
], '/favicon.ico': [ 'Cache-Control: public, max-age=86400' ] } } }
that will generate:
text
_headers
/* Referrer-Policy: origin X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; mode=block Access-Control-Allow-Origin: * X-Build: 1.0.1
/_nuxt/* Cache-Control: public, max-age=31536000, immutable
/sw.js Cache-Control: no-cache
/favicon.ico Cache-Control: public, max-age=86400
### Redirects
You can also add [redirects][netlify-redirects], as many as you like. You should pass in an array of objects with the redirection attributes. For example:
js { netlify: { redirects: [ { from: '/home', to: '/' }, { from: '/my-redirect', to: '/', status: 302, force: true }, { from: '/en/', to: '/en/404.html', status: 404 }, { from: '/', to: '/index.html', status: 200 }, { from: '/store', to: '/blog/:id', query: { id: ':id' } }, { from: '/', to: '/china', status: 302, conditions: { Country: 'cn,hk,tw' } } ] } }
will generate:
text
_redirects
/home / 301 /my-redirect / 302! /en/* /en/404.html 404 /* /index.html 200 /store id=:id /blog/:id 301 / /china 302 Country=cn,hk,tw ```
See the configuration section for all available options.
Documentation & Support
- ???? If you want extra details of how to configure and use this project, the full documentation is available at https://marquez.co/docs/nuxt-netlify/.
- ???? For Bug reports or Feature requests, use the Issues section.
- ???? For questions, you can also use the Issues section.
- ???? You may also want to follow me on Twitter.
Professional Support
This project is sponsored by me, a Full Stack Developer. If you require Professional Assistance on your project(s), please contact me at https://marquez.co.
Code of Conduct
Everyone participating in this project is expected to agree to abide by the Code of Conduct.
License
Code released under the MIT License.
[nuxt-docs-build-publicPath]: https://nuxtjs.org/api/configuration-build#publicPath