Skip to content

Commit a9930e4

Browse files
committed
Added support for CSS resources.
1 parent 2b661b9 commit a9930e4

File tree

6 files changed

+13
-36
lines changed

6 files changed

+13
-36
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ URL replacement for HTML Webpack Plugin
1212
This is an extension plugin for the [webpack](https://www.npmjs.com/package/webpack) plugin [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin) - a plugin that simplifies the creation of HTML files to serve your webpack bundles.
1313

1414
Typically, [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin) injects `<script>` and `<link>` elements into generated HTML.
15-
When used with a template, [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin) will still inject new elements regardless of whether or not the necessary `<script>` elements already exist.
15+
When used with a template, [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin) will still inject new elements regardless of whether or not elements already exist for the assets.
1616

1717
This plugin will automatically update the URLs for existing `<script>` and `<link>` elements in an HTML template with URLs generated by Webpack.
1818
It identifies existing elements by comparing their URLs with the generated output file name from Webpack. See Example section.
1919

20+
Webpack doesn't handle CSS resources natively.
21+
However, by using some of the following plugin combinations you can make them accessible to [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin):
22+
* copy-webpack-plugin ([npm](https://www.npmjs.com/package/copy-webpack-plugin)) ([github](https://github.com/webpack-contrib/copy-webpack-plugin)),<br>
23+
html-webpack-include-assets-plugin ([npm](https://www.npmjs.com/package/html-webpack-include-assets-plugin)) ([github](https://github.com/jharris4/html-webpack-include-assets-plugin))
24+
* extract-text-webpack-plugin ([npm](https://www.npmjs.com/package/extract-text-webpack-plugin)) ([github](https://github.com/webpack-contrib/extract-text-webpack-plugin)) (warning: untested)
25+
2026
Environment
2127
-----------
2228
* [node](https://nodejs.org/) >= 6.11.5
2329

24-
Dependencies
30+
Peer Dependencies
2531
------------
2632
* webpack ([npm](https://www.npmjs.com/package/webpack)) ([github](https://github.com/webpack/webpack)) >= 4.0.0
2733
* html-webpack-plugin ([npm](https://www.npmjs.com/package/html-webpack-plugin)) ([github](https://github.com/jantimon/html-webpack-plugin)) >= 3.2.0

index.js

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import webpack = require("webpack");
22
import {AsyncSeriesWaterfallHook} from "tapable";
3-
import {Configuration} from "webpack";
43
import * as path from "path";
54
import {ParsedPath} from "path";
65

@@ -40,26 +39,12 @@ interface HTMLPluginData {
4039

4140
}
4241

43-
/**
44-
*
45-
* @param {string} html The input HTML string.
46-
* @param {string[]} jsFiles
47-
* @param {webpack.Configuration} compilerOptions
48-
* @returns {string} The output HTML string.
49-
*/
5042
function replaceJS(html: string, jsFiles: string[], compilerOptions: webpack.Configuration): string {
5143
return replace(html, jsFiles, compilerOptions, /(<script[\S\s]*?src=['"])(.+?)(['"][^>]*?>)/gi);
5244
}
5345

54-
/**
55-
*
56-
* @param {string} html
57-
* @param {string[]} cssFiles
58-
* @param {webpack.Configuration} compilerOptions
59-
* @returns {string} The output HTML string.
60-
*/
6146
function replaceCSS(html: string, cssFiles: string[], compilerOptions: webpack.Configuration): string {
62-
return html;
47+
return replace(html, cssFiles, compilerOptions, /(<link[\S\s]*?href=['"])(.+?)(['"][^>]*?>)/gi);
6348
}
6449

6550
function replace(html: string, files: string[], compilerOptions: webpack.Configuration, regex: RegExp): string {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "replace-url-html-webpack-plugin",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"description": "Updates the URLs for existing script (JS) and link (CSS) elements in an HTML template with URLs generated by Webpack",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)