I'm trying to load bundle.js which contains the code compiled through webpack using jquery $.getScript
. However, it display blank page. But when I tried regular script tag then it works. The reason for using $.getScript
is because I have two environments and I want to load additional scripts only during production environment.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Single Page Program Demo</title>
<script src="../Programs/2999/js/jquery-2.2.3.min.js"></script>
<script>
/* Environment - (options: development / production) */
var env = 'development';
/* Load all scripts related to pi shell integration in sequence */
$.getMultiScripts = function(arr, path) {
var _arr = $.map(arr, function(scr) {
return $.getScript( (path||"") + scr );
});
_arr.push($.Deferred(function( deferred ){
$( deferred.resolve );
}));
return $.when.apply($, _arr);
}
var script_arr;
if (env == 'production'){
script_arr = [
'jquery-2.2.3.min.js',
'json2.js',
'jquery.validate.min.js',
'PIH.PIPlatform.ClientSideStorage.js',
'jquery.idletimer.js',
'jquery.idletimeout.js',
'DataTransfer.js',
'pi_utility.js',
'pi_data.js',
'bundle.js'
];
}
else {
script_arr = [
'bundle.js'
];
}
$.getMultiScripts(script_arr, '../Programs/2999/js/').done();
</script>
</head>
<body>
<div id="app"></div>
<!-- This works -->
<!-- <script src="../Programs/2999/js/bundle.js"></script> -->
</body>
</html>
也许使用RequireJS来管理你的脚本会更好。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.