项目作者: Tom-Bonnike

项目描述 :
A Netlify plugin to inline your assets/sources, built on top of the `inline-source` package.
高级语言: JavaScript
项目地址: git://github.com/Tom-Bonnike/netlify-plugin-inline-source.git
创建时间: 2020-05-06T11:17:28Z
项目社区:https://github.com/Tom-Bonnike/netlify-plugin-inline-source

开源协议:MIT License

下载


netlify-plugin-inline-source

A Netlify Build plugin to inline your assets/sources, built on top of the inline-source package. By default, it inlines and compresses tags that use the inline attribute and supports <script>, <link>, and <img>.

Inlining your assets/sources can lead to faster websites as it reduces the number of HTTP requests, at the cost of making your HTML files heavier. For best performance, you should usually only inline critical, render-blocking resources and let the rest load normally.
If you want to automatically extract and inline your critical CSS, you can use netlify-plugin-inline-critical-css.

  1. <html>
  2. <head>
  3. <!-- inline `styles.css` to a `<style>` tag -->
  4. <link inline href="styles.css" />
  5. <!-- inline `main.js` to a `<script>` tag -->
  6. <script inline src="main.js"></script>
  7. <!-- inline a remote file to a `<script>` tag -->
  8. <script inline src="https://some-website.com/script.js"></script>
  9. </head>
  10. <body>
  11. <!-- inline `image.png` to a `<img src="data:image/png;base64, …">` tag -->
  12. <img inline src="image.png" />
  13. <!-- inline `image.svg` to a `<svg>` tag -->
  14. <img inline src="image.svg" />
  15. </body>
  16. </html>

Usage and inputs

To install the plugin in the Netlify UI, use this direct in-app installation link or go to the Plugins directory.

For file-based installation, add it to your netlify.toml file.

  1. [[plugins]]
  2. package = "netlify-plugin-inline-source"
  3. # All inputs are optional, so you can omit this section.
  4. # Defaults are shown below.
  5. # You can also refer to the `inline-source` documentation: https://github.com/popeindustries/inline-source#usage.
  6. [plugins.inputs]
  7. # Attribute used to parse sources. All tags will be parsed if set to `false`.
  8. attribute = "inline"
  9. # Enable/disable compression of inlined content.
  10. compress = true
  11. # Maintain leading whitespace when `compress` is `false`.
  12. pretty = false
  13. # Disable inlining based on tag, type, and/or format.
  14. ignore = []
  15. # Convert `<img inline src="*.svg" />` to `<img>` and not `<svg>`.
  16. svgAsImage = false

To complete file-based installation, from your project’s base directory, use npm, yarn, or any other Node.js package manager to add the plugin to devDependencies in package.json.

  1. npm install -D netlify-plugin-inline-source

Once installed and configured, the plugin will automatically run for all of your site’s deploys.

Testing locally

To test this plugin locally, you can use the Netlify CLI:

  1. # Install the Netlify CLI.
  2. npm install netlify-cli -g
  3. # In the project working directory, run the build as Netlify would with the build bot.
  4. netlify build