问题
Calling require.js before knockout.js throws the following message:
Uncaught ReferenceError: ko is not defined
Assuming I have knockout.js at the very top of the combined file, I have this:
<script type="text/javascript" src="/bower_components/requirejs/require.js"></script>
<script type="text/javascript">
requirejs.config({
paths: {
text: '/bower_components/text/text'
},
});
requirejs([
'/bower_components/text/text.js'
]);
</script>
<script type="text/javascript" src="/js/dist/combined.min.js"></script>
回答1:
When Knockout detects RequireJS, it doesn't create a global ko
object but expects you to use define
to get the object.
来源:https://stackoverflow.com/questions/39515390/knockout-js-wont-be-recognized-after-using-require-js