Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101454384
InterpolateHtmlPlugin.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 10, 15:35
Size
1 KB
Mime Type
text/x-c++
Expires
Wed, Feb 12, 15:35 (2 d)
Engine
blob
Format
Raw Data
Handle
24150931
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
InterpolateHtmlPlugin.js
View Options
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// This webpack plugin lets us interpolate custom variables into `index.html`.
// Usage: `new InterpolateHtmlPlugin(HtmlWebpackPlugin, { 'MY_VARIABLE': 42 })`
// Then, you can use %MY_VARIABLE% in your `index.html`.
// It works in tandem with HtmlWebpackPlugin.
// Learn more about creating plugins like this:
// https://github.com/ampedandwired/html-webpack-plugin#events
'use strict'
;
const
escapeStringRegexp
=
require
(
'escape-string-regexp'
);
class
InterpolateHtmlPlugin
{
constructor
(
htmlWebpackPlugin
,
replacements
)
{
this
.
htmlWebpackPlugin
=
htmlWebpackPlugin
;
this
.
replacements
=
replacements
;
}
apply
(
compiler
)
{
compiler
.
hooks
.
compilation
.
tap
(
'InterpolateHtmlPlugin'
,
compilation
=>
{
this
.
htmlWebpackPlugin
.
getHooks
(
compilation
)
.
afterTemplateExecution
.
tap
(
'InterpolateHtmlPlugin'
,
data
=>
{
// Run HTML through a series of user-specified string replacements.
Object
.
keys
(
this
.
replacements
).
forEach
(
key
=>
{
const
value
=
this
.
replacements
[
key
];
data
.
html
=
data
.
html
.
replace
(
new
RegExp
(
'%'
+
escapeStringRegexp
(
key
)
+
'%'
,
'g'
),
value
);
});
});
});
}
}
module
.
exports
=
InterpolateHtmlPlugin
;
Event Timeline
Log In to Comment