tactivos / grunt-htmlrefs Goto Github PK
View Code? Open in Web Editor NEWReplaces (or removes) references to non-optimized scripts or stylesheets on HTML files
Replaces (or removes) references to non-optimized scripts or stylesheets on HTML files
Hi,
I'm using your plugin in the build script for one of my projects. I agree that sometimes the optimization steps are just too complicated to rely on the automatic concatenation & minification. This grunt task is exactly what I need.
However I just found out a little issue: in the HTML files, if I have multiple build:remove blocks, only the last block is removed. Looking into your code, I think it is because the blocks are stored in a hash object with build tags as keys, therefore the same build:remove tag is replaced with later-found ones.
My current workaround is adding a dummy parameter: e.g: to make the block's tag unique.
I think the plugin should make the multiple :remove block issue transparent to users by adding a unique id for the hash key (appending line number for example).
I leave this for your consideration.
BTW, thanks for the nice plugin. :)
with
the result is with false extension "styles.min.js"
with
the result is correct with "css" extension
What license is this released under? MIT?
Once again, great work!
First I want to thank you for the plugin, it very useful for me. But I don't see that you do something with assets that between build and enduild blocks. All you are doing is changing path url to a new assets that don't exist yet.
from:
to:
<!script type="text/javascript" src="/static/js/compiled/murally.js"></script>
But /static/js/compiled/murally.js does't exists. You need to concatenate all scripts to a single file.
The documentation of the includes feature is incorrect in the README. The example shows the following configuration:
grunt.initConfig({
htmlrefs: {
dist: {
/** @required - string including grunt glob variables */
src: './static/views/**/*.html',
/** @optional - string directory name*/
dest: './dist/static/views/',
/** @optional - references external files to be included */
includes: {
analytics: './ga.inc' // in this case it's google analytics (see sample below)
},
/** any other parameter included on the options will be passed for template evaluation */
options: {
buildNumber: 47878,
}
}
}
});
But the only way I found to make the include actually work is to place the includes
inside the options
(not sure if it's the doc or the code which is wrong):
grunt.initConfig({
htmlrefs: {
dist: {
/** @required - string including grunt glob variables */
src: './static/views/**/*.html',
/** @optional - string directory name*/
dest: './dist/static/views/',
/** any other parameter included on the options will be passed for template evaluation */
options: {
/** @optional - references external files to be included */
includes: {
analytics: './ga.inc' // in this case it's google analytics (see sample below)
},
buildNumber: 47878,
}
}
}
});
If you confirm it's a bug in the documentation, I can submit a pull request to fix it. Thanks for this really useful plugin.
Just checkin in: I have a pending pull request no one replied to, I'm trying to figure out if there is someone out there or it's just that my change is not needed
when specifying dest
as directory and not a file
htmlrefs: {
prod: {
src: '*.html',
dest: 'dist/',
}
},
I get the following error message:
Unable to write "dist/" file (Error code: EISDIR). Use --force to continue.
I want to use grunt-htmlrefs in my project but I use jade template. How can I use that plugin for handling jade templates?
File path with http:
prefix would get a wrong src, which is truncated.
<!-- build:js http://code.jquery.com/jquery.min.js -->
<script src="lib/jquery.min.js"></script>
<!-- endbuild -->
the result:
<script type="text/javascript" src="http"></script>
As I dig into the code, I found the reason. It uses colon to concatenate file type and file path, then splits later.
sections[[build[1], key.toString().trim()].join(':')] = last = [];
Anyway, it is not a big problem. My suggestion is using ::
instead of :
. You can use whatever you want.
Running: sudo npm install grunt-htmlrefs --save-dev
(with or without --save-dev
has the same outcome), I get the error that version 0.2.3 does not exist:
npm http GET https://registry.npmjs.org/grunt-htmlrefs
npm http 304 https://registry.npmjs.org/grunt-htmlrefs
npm http GET https://registry.npmjs.org/grunt-htmlrefs/-/grunt-htmlrefs-0.2.3.tgz
npm http 404 https://registry.npmjs.org/grunt-htmlrefs/-/grunt-htmlrefs-0.2.3.tgz
npm ERR! fetch failed https://registry.npmjs.org/grunt-htmlrefs/-/grunt-htmlrefs-0.2.3.tgz
npm ERR! Error: 404 Not Found
npm ERR! at null.<anonymous> (/usr/share/npm/lib/utils/fetch.js:47:16)
npm ERR! at EventEmitter.emit (events.js:126:20)
npm ERR! at WriteStream.flush (fs.js:1529:12)
npm ERR! at fs.close (/usr/share/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
npm ERR! at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Linux 3.5.0-17-generic
npm ERR! command "nodejs" "/usr/bin/npm" "install" "grunt-htmlrefs"
npm ERR! cwd /home/seb/projects/smp
npm ERR! node -v v0.8.16
npm ERR! npm -v 1.1.69
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/seb/projects/smp/npm-debug.log
npm ERR! not ok code 0
README file shows dest
parameter as optional but when not specifying it, it throws an error:
Running "htmlrefs:dist" (htmlrefs) task
Verifying property htmlrefs.dist exists in config...OK
Files: ./dist/index.html
Options: pkg={}, includes={}, buildNumber=47878
Reading ./dist/index.html...OK
Writing undefined...ERROR
Warning: Unable to write "undefined" file (Error code: undefined). Use --force to continue.
In addition to changing this in the README it would be better to actually throw the specific error, as undefined doesn't seem to be very explicit on what's wrong.
Insert grunt into devDependencies in package.json
Had to move a file to php to repsond to some $_SERVER vars and now htmlrefs is not working.
Hey there,
Great plugin -- it's really be a good experience working with this.
However, the main reason I'm using it is to replace an old requireJS tag with a new one. RequireJS tags look like this:
<script data-main="script/to/run/first" src="path/to/require.js"></script>
Basically, I would like to replace 'data-main' with the path to my newly minified file. Is there any way to support this?
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
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.