Giter Site home page Giter Site logo

preconnect-html-webpack-plugin's Introduction

preconnect-html-webpack-plugin

This extension plugin embeds <link rel="preconnect"> tags into HTML files generated by the HtmlWebpackPlugin. Supported in Webpack 3/4, html-webpack-plugin 3/4

安装

使用 npm 或者 yarn

$ npm install --save-dev preconnect-html-webpack-plugin

使用方式

在 webpack config 中添加插件:

const PreconnectHtmlWebpackPlugin = require('preconnect-html-webpack-plugin')

...

plugins: [
  // set the preconnect origins
  new PreconnectHtmlWebpackPlugin(['//test.a.com', '//test.b.com'])
]

HTML 注入效果

结合 html-webpack-plugin,它会自动在 html 注入你需要的配置

注意: 请把 preconnect-html-webpack-plugin 放在 html-webpack-plugin 插件后面使用

<link rel="preconnect" href="//test.a.com">
<link rel="preconnect" href="//test.b.com">

高级用法

const PreconnectHtmlWebpackPlugin = require('preconnect-html-webpack-plugin')

...

entry: {
  test1: './src/test1.js',
  test2: './src/test2.js'
},
plugins: [
  new HtmlWebpackPlugin({
    filename: 'test1.html',
    title: 'test1',
    template: './index.html',
    preconnect: [
      {
        url: '//test.a.com',
        crossorigin: true
      }
    ]
  }),
  new HtmlWebpackPlugin({
    filename: 'test2.html',
    title: 'test2',
    preconnect: [
      {
        url: '//test.a.com',
        crossorigin: true
      },
      '//test.b.com'
    ]
  }),
  new PreconnectHtmlWebpackPlugin()
]

new PreconnectHtmlWebpackPlugin() 中配置的属性将作用于所有 html 页面,并且优先级要高于 HtmlWebpackPlugin 中配置的 preconnect 属性

preconnect-html-webpack-plugin's People

Contributors

cn-kicoyu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.