File tree 4 files changed +42
-2
lines changed
4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change
1
+ node_modules
Original file line number Diff line number Diff line change 1
1
# HTML STRING REPLACE WEBPACK PLUGIN
2
2
3
+ [ ![ npm version] ( https://badge.fury.io/js/html-string-replace-webpack-plugin.svg )] ( https://badge.fury.io/js/html-string-replace-webpack-plugin )
4
+
3
5
This is a webpack plugin that replace string in html files that created by ` html-webpack-plugin ` .
4
6
This is especially useful for adding some cdn prefix.
5
7
@@ -69,6 +71,7 @@ new HtmlStringReplace({
69
71
// <script src="//cdn.baidu.com/static/build.js">
70
72
match: / src=\" ([^ \" ] * )\" / g ,
71
73
replacement: ' href="' + CDN_PREFIX + ' $1"'
74
+ }
72
75
]
73
76
})
74
77
```
Original file line number Diff line number Diff line change 4
4
"description" : " webpack html string replacement plugin" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "test" : " echo \" Error: no test specified \" && exit 1 "
7
+ "test" : " jest "
8
8
},
9
9
"repository" : {
10
10
"type" : " git" ,
21
21
"bugs" : {
22
22
"url" : " https://github.com/erraX/html-string-replace-webpack-plugin/issues"
23
23
},
24
- "homepage" : " https://github.com/erraX/html-string-replace-webpack-plugin#readme"
24
+ "homepage" : " https://github.com/erraX/html-string-replace-webpack-plugin#readme" ,
25
+ "dependencies" : {
26
+ "jest" : " ^20.0.4"
27
+ },
28
+ "jest" : {
29
+ "testRegex" : " (/test/.*\\ .spec.js)$"
30
+ }
25
31
}
Original file line number Diff line number Diff line change
1
+ var HtmlStringReplace = require ( '../lib/HtmlStringReplace' ) ;
2
+
3
+ describe ( 'test string replacement' , function ( ) {
4
+ it ( 'should replace string' , function ( ) {
5
+ var plugin = new HtmlStringReplace ( {
6
+ enable : true ,
7
+ patterns : [
8
+ {
9
+ // eg.
10
+ // <link href="build.css"> =>
11
+ // <link href="//cdn.baidu.com/static/build.css">
12
+ match : / h r e f = \" ( [ ^ \" ] * ) \" / g,
13
+ replacement : function ( match , $1 ) {
14
+ return 'href="//cdn.baidu.com/static/' + $1 + '"' ;
15
+ }
16
+ } ,
17
+ {
18
+ // eg.
19
+ // <script src="build.js"> =>
20
+ // <script src="//cdn.baidu.com/static/build.js">
21
+ match : / s r c = \" ( [ ^ \" ] * ) \" / g,
22
+ replacement : 'src="//cdn.baidu.com/static/$1"'
23
+ }
24
+ ]
25
+ } ) ;
26
+
27
+ expect ( plugin . replaceString ( '<link href="build.css">' ) ) . toBe ( '<link href="//cdn.baidu.com/static/build.css">' ) ;
28
+ expect ( plugin . replaceString ( '<script src="build.js">' ) ) . toBe ( '<script src="//cdn.baidu.com/static/build.js">' ) ;
29
+ } ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments