Przeglądaj źródła

Streamline javascript minifiy

Lucian I. Last 6 lat temu
rodzic
commit
710878c525
4 zmienionych plików z 65 dodań i 33 usunięć
  1. 1 0
      .gitignore
  2. 0 33
      examples/bookmarklet/source.js
  3. 8 0
      package.json
  4. 56 0
      src/source-pp.js

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 node_modules
 yarn.lock
 npm.lock
+/tmp
 *.log
 ~*

+ 0 - 33
examples/bookmarklet/source.js

@@ -1,33 +0,0 @@
-javascript:(function() {
-    var head = document.getElementsByTagName('head')[0],
-    _createScript = function(path, onload) {
-        var element = document.createElement('script');
-        element.src = path;
-        element.type = 'text/javascript';
-
-        if (onload) {
-            element.onload = onload;
-        }
-
-        head.appendChild(element);
-    },
-    _createStyle = function(path) {
-        var element = document.createElement('link');
-        element.href = path;
-        element.rel = 'stylesheet';
-        head.appendChild(element);
-    },
-    _createViewPort = function() {
-      var element = document.createElement('meta');
-      element.name = "viewport";
-      element.content = "width=device-width, initial-scale=1";
-      head.appendChild(element);
-    };
-
-    _createScript('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', function() {
-        ['https://cdn.rawgit.com/noelboss/featherlight/1.7.1/release/featherlight.min.js', 'https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autorun=false', 'https://cdn.rawgit.com/notifyjs/notifyjs/master/dist/notify.js', 'https://cdn.rawgit.com/noelboss/featherlight/1.7.1/release/featherlight.min.css', 'https://cdn.rawgit.com/dom111/webdav-js/master/assets/css/style-min.css', 'https://cdn.rawgit.com/dom111/webdav-js/master/src/webdav-min.js'].forEach(function(file) {
-            file.match(/css$/) ? _createStyle(file) : _createScript(file);
-        });
-    });
-    _createViewPort();
-})();

+ 8 - 0
package.json

@@ -1,4 +1,12 @@
 {
+  "scripts": {
+    "build:pp": "preprocess ./src/source-pp.js > ./tmp/source-local.js && preprocess ./src/source-pp.js -CDN=true > ./tmp/source-cdn.js",
+    "build:uglify": "uglifyjs ./tmp/source-local.js -o ./tmp/source-local-min.js -c -m -e && uglifyjs ./tmp/source-cdn.js -o ./tmp/source-cdn-min.js -c -m -e",
+    "build:bookmarklet": "echo -n 'javascript:' > ./examples/bookmarklet/source-min.js && cat ./tmp/source-cdn-min.js >> ./examples/bookmarklet/source-min.js",
+    "build:apache-cdn": "OUT=./examples/apache-directory-list/header.html; echo -n '<script type=\"text/javascript\">' > $OUT && cat ./tmp/source-cdn-min.js >> $OUT && echo -n '</script><!--' >> $OUT",
+    "build:apache-local": "OUT=./examples/apache-directory-list-local/header.html; echo -n '<script type=\"text/javascript\">' > $OUT && cat ./tmp/source-local-min.js >> $OUT && echo -n '</script><!--' >> $OUT",
+    "build": "npm run build:pp && npm run build:uglify && npm run build:bookmarklet && npm run build:apache-cdn && npm run build:apache-local"
+  },
   "devDependencies": {
     "preprocessor": "1.4.0",
     "uglify-js": "^3.4.9"

+ 56 - 0
src/source-pp.js

@@ -0,0 +1,56 @@
+var url_jquery, url_after
+// see https://www.npmjs.com/package/preprocessor for more information
+//
+// #ifdef CDN
+url_jquery = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
+url_after = [
+    'https://cdn.rawgit.com/noelboss/featherlight/1.7.1/release/featherlight.min.js',
+    'https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autorun=false',
+    'https://cdn.rawgit.com/notifyjs/notifyjs/master/dist/notify.js',
+    'https://cdn.rawgit.com/noelboss/featherlight/1.7.1/release/featherlight.min.css',
+    'https://cdn.rawgit.com/dom111/webdav-js/master/assets/css/style-min.css',
+    'https://cdn.rawgit.com/dom111/webdav-js/master/src/webdav-min.js'
+];
+// #else
+url_jquery = '/webdav-js/external/jquery.min.js';
+url_after = [
+    '/webdav-js/external/featherlight.min.js',
+    '/webdav-js/external/run_prettify.js',
+    '/webdav-js/external/notify.js',
+    '/webdav-js/external/featherlight.min.css',
+    '/webdav-js/assets/css/style-min.js',
+    '/webdav-js/external/webdav-min.js'
+];
+// #endif
+
+var head = document.getElementsByTagName('head')[0],
+_createScript = function(path, onload) {
+    var element = document.createElement('script');
+    element.src = path;
+    element.type = 'text/javascript';
+
+    if (onload) {
+        element.onload = onload;
+    }
+
+    head.appendChild(element);
+},
+_createStyle = function(path) {
+    var element = document.createElement('link');
+    element.href = path;
+    element.rel = 'stylesheet';
+    head.appendChild(element);
+},
+_createViewPort = function() {
+  var element = document.createElement('meta');
+  element.name = "viewport";
+  element.content = "width=device-width, initial-scale=1";
+  head.appendChild(element);
+};
+
+_createScript(url_jquery, function() {
+    url_after.forEach(function(file) {
+        file.match(/css$/) ? _createStyle(file) : _createScript(file);
+    });
+});
+_createViewPort();