nuzzio / grunt-strip-code Goto Github PK
View Code? Open in Web Editor NEWA GruntJS task to remove dev and test only code blocks from production builds
License: MIT License
A GruntJS task to remove dev and test only code blocks from production builds
License: MIT License
Documentation (README.md) tells we can configure under strip_code whereas strip_code task is a multi task declaration.
This from doc is invalid:
grunt.initConfig({
strip_code: {
options: {
start_comment: 'start-test-block',
end_comment: 'end-test-block',
},
src: 'dist/*.js'
},
})
This is valid:
grunt.initConfig({
strip_code: {
options: {
start_comment: 'start-test-block',
end_comment: 'end-test-block',
},
myTarget: {
src: 'dist/*.js'
}
},
})
There doesn't seem to be a way to have the src be recursive - without this, it is useless for larger projects. Is this something that can be added?
I am using the following example..
strip_code: { // jshint ignore:line
options: {
start_comment: 'start-remove', // jshint ignore:line
end_comment: 'end-remove', // jshint ignore:line
},
src: 'dist/js/sohoxi.js'
},
In my grunt file i combine a bunch of files into a dist folder...
grunt.registerTask('default', ['revision', 'jshint', 'sass', 'concat', 'strip_code',
So the strip_code task runs after concat. No matter what i try i get the error Warning: Unable to write "src" file (Error code: EISDIR). Use --force to continue.
So it seems it is unable to strip and replace in the same file?
Hi,
love this tool! (on my pc)
But on my coworker's pc it just won't strip.
all i see is: No code was stripped from file: ...
we tried a lot of things like using the cmd as admin. installing over and over again. But i have no idea why it won't strip?
He uses a pc with win 10.
I need test code to be stripped only from production files but remain in my source files. I could do concatenation to generate one file and then use the plugin to strip test code from it. But I use requirejs and I can't think of any way to achieve that. I need my sources to be already stripped from test code, because if run r.js first - it will delete all comments and I won't be able to use grunt-stip-code.
If I run grunt-strip-code first - I end up with my sources being stripped from test code and that's not what I want. Any ideas on how to achieve desired effect in this situation?
Lets say you have next code
//debug_start
"some code here";
//debug_start
...
//debug_start
"another debug code here";
//debug_end
Everybody know copy/paste is bad thing, but we still use it. So I would like to suggest
FR1: check if every "start" comment has its "end" pair
other example
//debug_start
"some code here";
//debug_start
"another code here";
//debug_end
"absolutely another code here";
//debug_end
In case any of *"code here" blocks contain half of '()' or '{}' debug may turn into nice quest :)
FR2: would be nice to have add check that forbids nesting of comments
I am newbie in grunt plugin development but I think would be nice to add those checks before actual replace and make them actually a required dependencies of replace (sub)task.
What do you think of this?
You can config the delimiters but the default pattern uses /* */ style commenting.
Can you add support to allow // comment as a option
The only other Grunt module I've found to do this is https://github.com/adamatnetrist/grunt-redacter, which doesn't appear to have much usage.
EDIT: Just noticed there is recent activity in the Develop branch. Going to give that a shot.
I think it should exclude binary files automatically. For several times, I destroied image files.
Hi,
I'm getting an error when passing an array of files in the config object. This is how it looks
grunt.initConfig({
strip_code : {
options : {
start_comment : 'start_remove_here',
end_comment : 'end_remove_here'
},
files : [{src:"scripts/a.js", dest : "scripts/a-strip.js"},{src:"scripts/b.js", dest : "scripts/b-strip.js"}]
},// strip_code end
});// init config end
And this is the error I'm getting:
Warning: Object #<Object> has no method 'indexOf'
Any help will be appreciated.
Thanks,
Rodrigo.
I found myself needing to make a more flexible version of your plugin that would accommodate dynamic comment blocks, and multiple types of those blocks.
I can submit a pull request if you are interested in them.
This is the repo: https://github.com/nuzzio/grunt-strip-code
Let me know,
Thanks
Hi!
I'm trying out your Grunt plugin and have the following problem.
First of all, this is my strip_code
configuration:
strip_code : {
options : {
pattern : /(\<\!--) @formatter:(off|on) -->/g
},
src : 'dist/index.html'
}
With this, I'm trying to remove IntelliJ's <!-- @formatter:on -->
commands.
If I get your documentation right, the strip_code
task should place the edited file on the same place which was defined in the src
attribute, however, strip_code
will save the new file as <root>/src
.
I don't get what I'm doing wrong here.
When attempting to strip a portion of a line using inline tagging, the newline is also stripped. This happens even if trailing white space is added at the end of the line
Example:
const var1 = "123"
const var2 /*begin_strip_tag*/ = "This is a string I want removed" /*end_strip_tag*/
will result in:
const var1 = "123"const var2
I would expect:
const var1 = "123"
const var2
Hi,
I'm trying out the grunt-strip-code library and I'm running into an issue and I'm running into an odd issue where if I nest my grunt-strip-code config like so:
grunt.initConfig({
strip_code: {
js: { /*... my settings */ }
}
})
and run the grunt task (e.g. grunt strip_code:js) it doesn't seem to find my file. But removing the sub task allows me to run grunt-strip-code fine.
When I run the command in verbose mode I get this output:
Running "strip_code:js" (strip_code) task
Verifying property strip_code.js exists in config...OK
File: [no files]
Options: testMode=false, intersectionCheck, parityCheck, locale="en_us", patterns=[], blocks=[{"start_block":"/* start-test-block end-test-block */"}], start_comment=false, end_comment=false, pattern=false, eol=""
I know this isn't a file path issue since removing the subtask block shouldn't affect what I define in your_target
but any thoughts on what could be happening? Let me know if there is more information you need.
i noticed this script replaces special characters like ฯ or unicode characters like this.
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.