-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments: preserveComments
option not working as expected
#366
Comments
I'm having this same issue... it appears that Uglify2 now only accepts three comments settings (ref):
The only way I was able to get it to work like the previous uglify: {
options: {
preserveComments: function(node, comment) {
// preserve comments that start with a bang
return /^!/.test( comment.value );
},
}
} Trying to use |
|
Note: Old post, code not working, use
uglify: {
options: {
output: {
comments: /^!/
}
}
} |
I don't think so. If you look at the code that starts at line 236: if (ARGS.comments != null) {
if (/^\/.*\/[a-zA-Z]*$/.test(ARGS.comments)) {
try {
OUTPUT_OPTIONS.comments = extractRegex(ARGS.comments);
} catch (e) {
print_error("ERROR: Invalid --comments: " + e.message);
}
} else if (ARGS.comments == "all") { It uses The function extractRegex(str) {
if (/^\/.*\/[a-zA-Z]*$/.test(str)) {
var regex_pos = str.lastIndexOf("/");
return new RegExp(str.substr(1, regex_pos - 1), str.substr(regex_pos + 1));
} else {
throw new Error("Invalid regular expression: " + str);
}
} is testing for a string again, but it must start with a |
That's the case if grunt uses the cli to communicate to uglifyjs, with the api, it can directly call the uglifyjs api and bypass the cli options (avoiding to parse such things). |
Uh... I see that this project is using its own minifier instead of UglifyJS's minify function. It's using this: https://github.com/gruntjs/grunt-contrib-uglify/blob/master/tasks/lib/uglify.js. Need some time to investigate stuff here before I can say more... |
For WordPress the issue is now resolved via https://core.trac.wordpress.org/changeset/35564 Which is to use: Related: #190 preserveComments:'some' removes subsequent /*! */ comments |
The README.md needs to be updated as well as it still includes @avdg shouldn't this be
|
uh, that's because I mixed up the UglifyJS.minify options with grunt-contrib-uglify options. Cleaning up... |
To those dealing with this issue, the full "some" behavior as documented should be something like this: grunt.initConfig({
uglify: {
options: {
preserveComments: /(?:^!|@(?:license|preserve|cc_on))/
},
files: []
}
}); |
Adding all locales Renaming core to core-lite as well Had an issue with uglify output similar to gruntjs/grunt-contrib-uglify#366 I've verified now output is identical to the uglifyjs command used so far
Updating to v0.10.0 causes some issues with the
preserveComments
option:The Grunt task
grunt uglify:jqueryui
produces minified files that include comments that start with//
, previously in v0.9.2 these comments were stripped.e.g Using
preserveComments: 'some'
: (Truncated for readability, full diff is here)Changing the task config to
preserveComments: 'all'
orpreserveComments: false
the results are correct and expected with all comments kept or removed respectively.The above is based on following configuration (again truncated for readability) the full WordPress grunt task configuration is here Gruntfile.js#L411 (unchanged for v0.10.0)
The text was updated successfully, but these errors were encountered: