-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
71 lines (66 loc) · 2.58 KB
/
Gruntfile.js
File metadata and controls
71 lines (66 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
module.exports = function (grunt) {
// Load package.json
grunt.file.defaultEncoding = "utf8";
grunt.file.preserveBOM = false;
grunt.initConfig({
// Read package.json for metadata
pkg: grunt.file.readJSON("package.json"),
// JavaScript minification with UglifyJS
uglify: {
options: {
banner:
"/*! <%= pkg.name %> - v<%= pkg.version %> - " +
"<%= grunt.template.today(\"yyyy-mm-dd\") %> */\n",
report: "gzip",
compress: {
drop_console: false, // Keep console logs for WordPress debug
drop_debugger: true,
dead_code: true,
unused: true
},
mangle: {
reserved: ["jQuery", "$", "window", "document"] // Preserve WordPress globals
},
sourceMap: false, // No source maps for production
preserveComments: function(node, comment) {
// Preserve license headers and important comments
return comment.value.match(/^!|@preserve|@license|@cc_on/i);
}
},
admin: {
files: {
"assets/js/admin.min.js": ["assets/js/admin.js"]
}
},
passwordValidation: {
files: {
"assets/js/password-validation.min.js": ["assets/js/password-validation.js"]
}
},
captcha: {
files: {
"assets/js/captcha.min.js": ["assets/js/captcha.js"]
}
}
}
});
// Load grunt plugins
grunt.loadNpmTasks("grunt-contrib-uglify");
// Register tasks
grunt.registerTask("js", ["uglify"]);
grunt.registerTask("default", ["uglify"]);
grunt.registerTask("minify", ["uglify"]);
// Custom task to show minification results
grunt.registerTask("build", "Build minified assets", function() {
grunt.task.run(["uglify"]);
grunt.log.writeln("");
grunt.log.writeln("✨ JavaScript minification completed successfully!");
grunt.log.writeln("📦 Generated files:");
grunt.log.writeln(" • assets/js/admin.min.js");
grunt.log.writeln(" • assets/js/password-validation.min.js");
grunt.log.writeln("");
grunt.log.writeln("ℹ CSS minification: Run 'npm run minify:css' separately");
grunt.log.writeln("🚀 Ready for production build!");
});
};