How to use html-webpack-plugin variable inside ?
up vote
0
down vote
favorite
I am trying to assign variable inside <script>
tag by means of html-webpack-plugin where the variable is located.
I can easily use it inside html tags like title <%= htmlWebpackPlugin.options.applicationId %>
My html-webpack-plugin looks like :
new HtmlWebpackPlugin(
filename: config.build.index,
template: 'index.html',
inject: true,
applicationId : process.env.APPLICATION_ID ?process.env.APPLICATION_ID : 1,
minify:
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
,
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
),
And I want to use variable applicationId on index.html page with following script :
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
if (xhr.readyState == XMLHttpRequest.DONE)
document.write(xhr.responseText);
;
var appId = <%= htmlWebpackPlugin.options.applicationId %>;
xhr.open("GET","https://somesite.com/NavigationApi/api/content/get?applicationId=" + appId,false);
xhr.send(null);
</script>
javascript webpack html-webpack-plugin
add a comment |
up vote
0
down vote
favorite
I am trying to assign variable inside <script>
tag by means of html-webpack-plugin where the variable is located.
I can easily use it inside html tags like title <%= htmlWebpackPlugin.options.applicationId %>
My html-webpack-plugin looks like :
new HtmlWebpackPlugin(
filename: config.build.index,
template: 'index.html',
inject: true,
applicationId : process.env.APPLICATION_ID ?process.env.APPLICATION_ID : 1,
minify:
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
,
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
),
And I want to use variable applicationId on index.html page with following script :
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
if (xhr.readyState == XMLHttpRequest.DONE)
document.write(xhr.responseText);
;
var appId = <%= htmlWebpackPlugin.options.applicationId %>;
xhr.open("GET","https://somesite.com/NavigationApi/api/content/get?applicationId=" + appId,false);
xhr.send(null);
</script>
javascript webpack html-webpack-plugin
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to assign variable inside <script>
tag by means of html-webpack-plugin where the variable is located.
I can easily use it inside html tags like title <%= htmlWebpackPlugin.options.applicationId %>
My html-webpack-plugin looks like :
new HtmlWebpackPlugin(
filename: config.build.index,
template: 'index.html',
inject: true,
applicationId : process.env.APPLICATION_ID ?process.env.APPLICATION_ID : 1,
minify:
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
,
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
),
And I want to use variable applicationId on index.html page with following script :
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
if (xhr.readyState == XMLHttpRequest.DONE)
document.write(xhr.responseText);
;
var appId = <%= htmlWebpackPlugin.options.applicationId %>;
xhr.open("GET","https://somesite.com/NavigationApi/api/content/get?applicationId=" + appId,false);
xhr.send(null);
</script>
javascript webpack html-webpack-plugin
I am trying to assign variable inside <script>
tag by means of html-webpack-plugin where the variable is located.
I can easily use it inside html tags like title <%= htmlWebpackPlugin.options.applicationId %>
My html-webpack-plugin looks like :
new HtmlWebpackPlugin(
filename: config.build.index,
template: 'index.html',
inject: true,
applicationId : process.env.APPLICATION_ID ?process.env.APPLICATION_ID : 1,
minify:
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
,
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
),
And I want to use variable applicationId on index.html page with following script :
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
if (xhr.readyState == XMLHttpRequest.DONE)
document.write(xhr.responseText);
;
var appId = <%= htmlWebpackPlugin.options.applicationId %>;
xhr.open("GET","https://somesite.com/NavigationApi/api/content/get?applicationId=" + appId,false);
xhr.send(null);
</script>
javascript webpack html-webpack-plugin
javascript webpack html-webpack-plugin
asked 14 hours ago
Self_taught
176
176
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224037%2fhow-to-use-html-webpack-plugin-variable-inside-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password