瀏覽代碼

UglifyJS now invoked by webpack instead of Grunt

n1474335 8 年之前
父節點
當前提交
9bd11dc7ad
共有 5 個文件被更改,包括 46 次插入73 次删除
  1. 34 51
      Gruntfile.js
  2. 0 20
      build/prod/scripts.js
  3. 0 0
      build/prod/styles.css
  4. 0 1
      package.json
  5. 12 1
      src/web/index.js

+ 34 - 51
Gruntfile.js

@@ -8,7 +8,7 @@ module.exports = function (grunt) {
     // Tasks
     grunt.registerTask("dev",
         "A persistent task which creates a development build whenever source files are modified.",
-        ["clean:dev", "webpack:web", "copy:htmlDev", "copy:staticDev", "chmod:build", "watch"]);
+        ["clean:dev", "copy:htmlDev", "copy:staticDev", "chmod:build", "webpack:webDev", "watch"]);
 
     grunt.registerTask("node",
         "Compiles CyberChef into a single NodeJS module.",
@@ -20,8 +20,8 @@ module.exports = function (grunt) {
 
     grunt.registerTask("prod",
         "Creates a production-ready build. Use the --msg flag to add a compile message.",
-        ["eslint", "test", "exec:stats", "clean", "jsdoc", "webpack:web", "copy:htmlDev", "copy:htmlProd", "copy:htmlInline",
-         "copy:staticDev", "copy:staticProd", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod"]);
+        ["eslint", "test", "exec:stats", "clean", "jsdoc", "webpack:webProd", "copy:htmlDev", "copy:htmlProd", "copy:htmlInline",
+         "copy:staticDev", "copy:staticProd", "cssmin", "inline", "htmlmin", "chmod"]);
 
     grunt.registerTask("docs",
         "Compiles documentation in the /docs directory.",
@@ -29,7 +29,7 @@ module.exports = function (grunt) {
 
     grunt.registerTask("stats",
         "Provides statistics about the code base such as how many lines there are as well as details of file sizes before and after compression.",
-        ["webpack:web", "uglify:prod", "exec:stats", "exec:repoSize", "exec:displayStats"]);
+        ["webpack:webDev", "webpack:webProd", "exec:stats", "exec:repoSize", "exec:displayStats"]);
 
     grunt.registerTask("release",
         "Prepares and deploys a production version of CyberChef to the gh-pages branch.",
@@ -50,7 +50,6 @@ module.exports = function (grunt) {
     grunt.loadNpmTasks("grunt-contrib-clean");
     grunt.loadNpmTasks("grunt-webpack");
     grunt.loadNpmTasks("grunt-contrib-copy");
-    grunt.loadNpmTasks("grunt-contrib-uglify");
     grunt.loadNpmTasks("grunt-contrib-cssmin");
     grunt.loadNpmTasks("grunt-contrib-htmlmin");
     grunt.loadNpmTasks("grunt-inline-alt");
@@ -141,6 +140,7 @@ module.exports = function (grunt) {
                         COMPILE_TIME: JSON.stringify(compileTime),
                         COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || "")
                     }),
+                    new ExtractTextPlugin("styles.css"),
                 ],
                 resolve: {
                     alias: {
@@ -154,24 +154,7 @@ module.exports = function (grunt) {
                             exclude: /node_modules/,
                             loader: "babel-loader?compact=false"
                         }
-                    ]
-                }
-            },
-            web: {
-                target: "web",
-                entry: [
-                    "babel-polyfill",
-                    "bootstrap",
-                    "bootstrap-switch",
-                    "bootstrap-colorpicker",
-                    "./src/web/css/index.js",
-                    "./src/web/index.js"
-                ],
-                output: {
-                    filename: "scripts.js",
-                    path: "build/dev"
-                },
-                module: {
+                    ],
                     rules: [
                         {
                             test: /\.css$/,
@@ -196,9 +179,33 @@ module.exports = function (grunt) {
                             }
                         }
                     ]
+                }
+            },
+            webDev: {
+                target: "web",
+                entry: "./src/web/index.js",
+                output: {
+                    filename: "scripts.js",
+                    path: "build/dev"
+                }
+            },
+            webProd: {
+                target: "web",
+                entry: "./src/web/index.js",
+                output: {
+                    filename: "scripts.js",
+                    path: "build/prod"
                 },
                 plugins: [
-                    new ExtractTextPlugin("styles.css"),
+                    new webpack.optimize.UglifyJsPlugin({
+                        compress: {
+                            "screw_ie8": true,
+                            "dead_code": true,
+                            "unused": true,
+                            "warnings": false
+                        },
+                        comments: false,
+                    }),
                 ]
             },
             tests: {
@@ -307,30 +314,6 @@ module.exports = function (grunt) {
                 dest: "build/prod/index.html"
             }
         },
-        uglify: {
-            options: {
-                preserveComments: function (node, comment) {
-                    if (comment.value.indexOf("* @license") === 0) return true;
-                    return false;
-                },
-                screwIE8: true,
-                ASCIIOnly: true,
-                beautify: {
-                    beautify: false,
-                    inline_script: true, // eslint-disable-line camelcase
-                    ascii_only: true, // eslint-disable-line camelcase
-                    screw_ie8: true // eslint-disable-line camelcase
-                },
-                compress: {
-                    screw_ie8: true // eslint-disable-line camelcase
-                },
-                banner: banner
-            },
-            prod: {
-                src: "build/dev/scripts.js",
-                dest: "build/prod/scripts.js"
-            }
-        },
         cssmin: {
             prod: {
                 src: "build/dev/styles.css",
@@ -444,11 +427,11 @@ module.exports = function (grunt) {
         watch: {
             css: {
                 files: ["src/web/css/**/*.css", "src/web/css/**/*.less"],
-                tasks: ["webpack:web", "chmod:build"]
+                tasks: ["webpack:webDev", "chmod:build"]
             },
             js: {
                 files: "src/**/*.js",
-                tasks: ["webpack:web", "chmod:build"]
+                tasks: ["webpack:webDev", "chmod:build"]
             },
             html: {
                 files: "src/web/html/**/*.html",
@@ -460,7 +443,7 @@ module.exports = function (grunt) {
             },
             grunt: {
                 files: "Gruntfile.js",
-                tasks: ["clean:dev", "webpack:web", "copy:htmlDev", "copy:staticDev", "chmod:build"]
+                tasks: ["clean:dev", "webpack:webDev", "copy:htmlDev", "copy:staticDev", "chmod:build"]
             }
         },
     });

文件差異過大導致無法顯示
+ 0 - 20
build/prod/scripts.js


文件差異過大導致無法顯示
+ 0 - 0
build/prod/styles.css


+ 0 - 1
package.json

@@ -40,7 +40,6 @@
     "grunt-contrib-copy": "~1.0.0",
     "grunt-contrib-cssmin": "~1.0.2",
     "grunt-contrib-htmlmin": "~2.0.0",
-    "grunt-contrib-uglify": "~2.0.0",
     "grunt-contrib-watch": "~1.0.0",
     "grunt-eslint": "^19.0.0",
     "grunt-exec": "~1.0.1",

+ 12 - 1
src/web/index.js

@@ -4,10 +4,21 @@
  * @license Apache-2.0
  */
 
+// CSS
+import "./css/index.js";
+
+// Libs
+import "babel-polyfill";
+import "bootstrap";
+import "bootstrap-switch";
+import "bootstrap-colorpicker";
+import CanvasComponents from "../core/lib/canvascomponents.js";
+
+// CyberChef
 import App from "./App.js";
 import Categories from "../core/config/Categories.js";
 import OperationConfig from "../core/config/OperationConfig.js";
-import CanvasComponents from "../core/lib/canvascomponents.js";
+
 
 /**
  * Main function used to build the CyberChef web app.

部分文件因文件數量過多而無法顯示