├── .prettierrc
├── LICENSE
├── README.md
├── index.js
└── package.json
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 100,
3 | "semi": false,
4 | "singleQuote": true,
5 | "tabWidth": 2,
6 | "trailingComma": "none",
7 | "arrowParens": "avoid"
8 | }
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 nathanie
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [html-replace-webpack-plugin]
2 |
3 | A Webpack plugin for replace HTML contents with custom pattern string or regex.
4 |
5 | ## Examples
6 |
7 | https://github.com/iminif/html-replace-webpack-plugin-howto
8 |
9 | ## :green_heart: Special Note! :eyes:
10 |
11 | This plugin works together with [html-webpack-plugin]!
12 |
13 | ## Usage
14 |
15 | First of all, you need both `html-webpack-plugin` and `html-replace-webpack-plugin`.
16 |
17 | ```shell
18 | npm i -D html-webpack-plugin html-replace-webpack-plugin
19 | ```
20 |
21 | Then, add it to your `webpack.config.js` file:
22 |
23 | ### In your `webpack.config.js` file:
24 |
25 | > :green_heart: Please ensure that `html-webpack-plugin` was placed before `html-replace-webpack-plugin` in your Webpack config if you were working with Webpack 4.x!
26 |
27 | ```javascript
28 | var webpack = require('webpack')
29 | var HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin')
30 |
31 | // file types & file links
32 | const resource = {
33 | js: { bootstrap: '//cdn/bootstrap/bootstrap.min.js' },
34 | css: { bootstrap: '//cdn/bootstrap/bootstrap.min.css' },
35 | img: { 'the-girl': '//cdn/img/the-girl.jpg' }
36 | }
37 |
38 | const tpl = {
39 | img: '',
40 | css: '',
41 | js: ''
42 | }
43 |
44 | module.exports = {
45 | // Definition for Webpack plugins
46 | plugin: [
47 | new HtmlWebpackPlugin({
48 | /* configs */
49 | }),
50 | // Replace html contents with string or regex patterns
51 | new HtmlReplaceWebpackPlugin([
52 | {
53 | pattern: 'foo',
54 | replacement: '`foo` has been replaced with `bar`'
55 | },
56 | {
57 | pattern: '@@title',
58 | replacement: 'html replace webpack plugin'
59 | },
60 | {
61 | pattern: /
(.+?)<\/p>/g, // /g => replace all
62 | replacement: '