From d3fac3964c55b8d5c3fc2eb5a19eff1a0a1ac7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=AF=97=E5=B7=9D?= Date: Fri, 20 Jul 2018 13:03:21 +0800 Subject: [PATCH] feat: allow specify inject position --- README.md | 2 ++ src/lib/insert-links-into-head.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 21dfac1..0d8d91e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ This is a fork of [preload-webpack-plugin](https://github.com/GoogleChromeLabs/p - Added an `includeHtmlNames` option so that the plugin is only applied to a specific HTML file. +- If you want to specify the inject position of preload/prefetch tags in your html, add `` html comment tags in your [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) template file, and it will be replaced by preload/prefetch resources tags. + - Drops support for Node < 6. --- diff --git a/src/lib/insert-links-into-head.js b/src/lib/insert-links-into-head.js index 9db83fa..ea108a8 100644 --- a/src/lib/insert-links-into-head.js +++ b/src/lib/insert-links-into-head.js @@ -20,6 +20,11 @@ function insertLinksIntoHead({html, links=[]}) { return html; } + if (html.match(//)) { + //If there's a to specify inject position, replace it with links + return html.replace(//, links.join('')); + } + if (html.includes('')) { // If a valid closing is found, insert the new s right before it. return html.replace('', links.join('') + '');