scott-laursen / grunt-scriptlinker Goto Github PK
View Code? Open in Web Editor NEWGrunt plugin for autoinsertion of script tags in an html file
License: MIT License
Grunt plugin for autoinsertion of script tags in an html file
License: MIT License
Instead of creating whole block we could setup grunt watch and listen to added
or deleted
event and add/remove script.
grunt.event.on('watch', function(action, filepath) {
if(action == 'added'){
//add script
}
if( action == 'deleted'){
//remove script
}
});
I always kind of wanted this when I was inserting js/css files into my HTML file, but now that I'm trying to conditionalize our chrome extension's build, the file I'm trying to replace in is manifest.json. JSON doesn't allow for comments, so I need those start/end comment lines to be removed as well once the files get inserted. Since the resulting JSON file isn't valid, I can't JSON parse it (which my build does later on) and the chrome extension store won't accept it (I would have to manually remove the comment tags).
I have a pull request coming that has an option added. Feel free to give the option a better name or something.
Here's my config:
var javascriptLoadOrder = [
'src/main/resources/vendor/**/*.js',
'src/main/resources/app/js/Constants.js',
'src/main/resources/app/js/Random.js',
'src/main/resources/app/js/Vector.js',
'src/main/resources/app/js/Resources.js',
'src/main/resources/app/js/StatsData.js',
'src/main/resources/**/*.js'
];
//...
scriptlinker: {
app: {
options: {
startTag: '<!--SCRIPTS-->',
endTag: '<!--SCRIPTS END-->',
fileTmpl: '<script src="%s"></script>\n',
appRoot: 'src/main/generated'
},
src: javascriptLoadOrder,
dest: 'src/main/generated/foo.html',
cwd: '.',
flatten: true
}
}
In the destination file, the javascript files have this path:
<script src="src/main/resources/vendor/js/jquery-2.0.2.min.js"></script>
<script src="src/main/resources/vendor/js/jquery-ui.js"></script>
<script src="src/main/resources/vendor/js/jquery.hammer.min.js"></script>
<script src="src/main/resources/vendor/js/lodash.min.js"></script>
<script src="src/main/resources/app/js/Constants.js"></script>
<script src="src/main/resources/app/js/Random.js"></script>
This is correct relative to the gruntfile, but that's not what I asked for. It seems to have ignored what I set appRoot
to. Instead, they should look like this:
<script src="../resources/vendor/js/jquery-2.0.2.min.js" type="text/javascript"></script>
...
Or , maybe I'm just misunderstanding how to use the tool.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.