├── .gitignore
├── LICENSE
├── README.md
├── VueCliPluginHTMLReplace.js
├── index.js
├── package.json
└── utils.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
3 | *.log*
4 |
5 | .idea
6 | .vscode
7 | *.suo
8 | *.ntvs*
9 | *.njsproj
10 | *.sln
11 | *.sw*
12 |
13 | .DS_Store
14 | .DS_Store?
15 | ._*
16 | .Spotlight-V100
17 | .[Tt]rashes
18 | eh[Tt]humbs.db
19 | [Tt]humbs.db
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018-present Tristan Pavard
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 | [](https://www.npmjs.com/package/vue-cli-plugin-html-replace)
2 | [](https://github.com/tpavard/vue-cli-plugin-html-replace/blob/master/LICENSE)
3 |
4 | > [!CAUTION]
5 | > This project is not maintained anymore.
6 | > Please use a modern solution like [unplugin-replace](https://github.com/unplugin/unplugin-replace).
7 |
8 | # Vue-cli Plugin HTML Replace
9 |
10 | A simple plugin to replace contents within your HTML files generated by [Vue CLI](https://github.com/vuejs/vue-cli).
11 |
12 | > [!TIP]
13 | > You might not need this plugin for simple cases.
14 | > See [env variables interpolation](https://cli.vuejs.org/guide/html-and-static-assets.html#interpolation).
15 |
16 | - [Getting started](#getting-started)
17 | - [Configuration](#configuration)
18 | - [Basic usage](#basic-usage)
19 | - [Multi-page mode](#multi-page-mode)
20 | - [API](#api)
21 | - [Global](#global)
22 | - [Pattern](#pattern)
23 |
24 | ## Getting started
25 |
26 | :warning: Make sure you have [Vue CLI 3.x.x](https://github.com/vuejs/vue-cli) installed:
27 |
28 | ```
29 | vue -V
30 | ```
31 |
32 | Navigate to your vue app folder and add the cli plugin:
33 |
34 | ```
35 | vue add html-replace
36 | ```
37 | ## Configuration
38 |
39 | ### Basic usage
40 |
41 | This plugin can be configured by defining `htmlReplace` via the `pluginOptions` in your `vue.config.js`.
42 |
43 | The `patterns` property must either be an object or an array of objects. Each pattern must contain both `match` and `replacement` options, otherwise it will be ignored.
44 |
45 | ```javascript
46 | module.exports = {
47 | pluginOptions: {
48 | htmlReplace: {
49 | enable: (process.env.NODE_ENV === "production"),
50 | patterns: [
51 | {
52 | match: "foo",
53 | replacement: "bar",
54 | },
55 | {
56 | match: /any/g,
57 | replacement: "Globally replaced",
58 | },
59 | {
60 | match: /
(.*)<\/title>/,
61 | replacement: (match, $1) => `"${$1}" has been replaced.`,
62 | },
63 | ],
64 | },
65 | },
66 | };
67 | ```
68 |
69 | ### Multi-page mode
70 |
71 | In case you'd need to prevent patterns to be applied to some of your pages, you can specify either one of `excludes` or `includes` options. If both options are set, then `excludes` will be ignored.
72 |
73 | Each entry must be named after the key given for the page(s) to be excluded/included. These properties are optional and will be ignored when you're not building your app in multi-page mode. Thus all the patterns would be applied to your HTML files.
74 |
75 | ```javascript
76 | module.exports = {
77 | pages: {
78 | index: {
79 | entry: "src/App_1/main.js",
80 | filename: "app_1.html"
81 | },
82 | app_2: "src/App_2/main.js",
83 | app_3: "src/App_3/main.js",
84 | },
85 | pluginOptions: {
86 | htmlReplace: {
87 | patterns: [
88 | {
89 | match: "foo",
90 | replacement: "All of your pages will be affected",
91 | },
92 | {
93 | match: /.*<\/title>/,
94 | replacement: "This is the index page",
95 | includes: "index",
96 | },
97 | {
98 | match: /.*<\/title>/,
99 | replacement: "This is the second page",
100 | excludes: ["index" , "app_3"],
101 | },
102 | ],
103 | },
104 | },
105 | };
106 | ```
107 |
108 | ## API
109 |
110 | ### Global
111 |
112 | | Name | Type | Default | Description |
113 | | :--: | :--: | :--: | --- |
114 | | `enable` | `Boolean` | `true` | Enables/disables the plugin. |
115 | | `patterns` | `Object` \| `Array