Reputation: 9413
I have a complex JS-project that is written in AMD form. It uses RequireJS.
My system should be able to include it's functionality to different external sites. I want to compile it to a single js-file and include it like this:
<script type="text/javascript" src="http://mysystem.com/core-build.js"></script>
I don't know if an external site has requirejs or not, that's why it seems that requirejs itself should be included into core-build.js. Compiled file should be completely independ on the environment.
From the other side, it should not redefine an external site environment. My system uses jquery, knockout, and theese libraries should be defined locally for my system purposes only. They should not affect the site's global namespace.
So my question is how to optimize scripts to one file, include requirejs itself in it and wrap everything into a local namespace?
Upvotes: 4
Views: 478
Reputation: 44589
You could use the Grunt concat
task:
concat: {
dist: {
src: [
"www/assets/js/libs/require.js",
"dist/debug/app.js"
],
dest: "www/app_build.js",
separator: ";"
}
}
You can see an example app setup on Backbone Boilerplate (even if you're not using Backbone).
Upvotes: 3