Ver código fonte

Minification of the bundle, npm-run-all

Artur Paikin 9 anos atrás
pai
commit
7cdbe9623b
3 arquivos alterados com 104 adições e 13 exclusões
  1. 26 0
      bin/build-css.js
  2. 59 0
      bin/build-js.js
  3. 19 13
      package.json

+ 26 - 0
bin/build-css.js

@@ -0,0 +1,26 @@
+var sass = require('node-sass')
+var postcss = require('postcss')
+var autoprefixer = require('autoprefixer')
+var cssnano = require('cssnano')
+var chalk = require('chalk')
+var fs = require('fs')
+var mkdirp = require('mkdirp')
+
+mkdirp.sync('./dist/')
+
+function handleErr (err) {
+  console.error(chalk.red('✗ Error:'), chalk.red(err.message))
+}
+
+sass.render({file: './src/scss/uppy.scss'}, function (err, sassResult) {
+  if (err) handleErr(err)
+  postcss([ cssnano, autoprefixer ])
+    .process(sassResult.css)
+    .then(function (postCSSResult) {
+      postCSSResult.warnings().forEach(function (warn) {
+        console.warn(warn.toString())
+      })
+      fs.writeFileSync('./dist/uppy.min.css', postCSSResult.css)
+      console.info(chalk.green('✓ Built Uppy CSS:'), chalk.magenta('uppy.min.css'))
+    })
+})

+ 59 - 0
bin/build-js.js

@@ -0,0 +1,59 @@
+var path = require('path')
+var fs = require('fs')
+var babelify = require('babelify')
+var chalk = require('chalk')
+var mkdirp = require('mkdirp')
+var glob = require('glob')
+var browserify = require('browserify')
+// var rollupify = require('rollupify')
+
+mkdirp.sync('./dist/')
+
+function handleErr (err) {
+  console.error(chalk.red('✗ Error:'), chalk.red(err.message))
+}
+
+function buildUppyBundle () {
+  browserify('./src/index.js', { debug: true, standalone: 'Uppy' })
+    .plugin('minifyify', {
+      map: 'uppy.js.map',
+      output: './dist/uppy.js.map'
+    })
+    // .transform(rollupify)
+    .transform(babelify)
+    .on('error', handleErr)
+    .bundle()
+    // .pipe(exorcist('./dist/uppy.js.map'))
+    .pipe(fs.createWriteStream('./dist/uppy.min.js', 'utf8'))
+    .on('error', handleErr)
+    .on('finish', function () {
+      console.info(chalk.green('✓ Built Uppy bundle:'), chalk.magenta('uppy.min.js'))
+    })
+}
+
+function buildUppyLocales () {
+  mkdirp.sync('./dist/locales')
+  glob('./src/locales/*.js', function (err, files) {
+    if (err) console.log(err)
+    files.forEach(function (file) {
+      var fileName = path.basename(file, '.js')
+      browserify(file, { debug: true })
+        .plugin('minifyify', {
+          map: fileName + '.min.js.map',
+          output: './dist/locales/' + fileName + '.min.js.map'
+        })
+        // .transform(rollupify)
+        .transform(babelify)
+        .on('error', handleErr)
+        .bundle()
+        .pipe(fs.createWriteStream('./dist/locales/' + fileName + '.min.js', 'utf8'))
+        .on('error', handleErr)
+        .on('finish', function () {
+          console.info(chalk.green('✓ Built Uppy locale:'), chalk.magenta(fileName + '.min.js'))
+        })
+    })
+  })
+}
+
+buildUppyBundle()
+buildUppyLocales()

+ 19 - 13
package.json

@@ -4,13 +4,13 @@
   "description": "Almost as cute as a Puppy :dog:",
   "main": "src/index.js",
   "scripts": {
+    "build:bundle": "node ./bin/build-js.js",
+    "build:css": "node ./bin/build-css.js",
+    "size": "echo 'JS Size:' && cat ./dist/uppy.min.js | gzip | wc -c && echo 'CSS Size:' && cat ./dist/uppy.min.css | gzip | wc -c",
     "build:bundle:fullpath": "env OUT=uppy-fp.js ./bin/build-bundle --full-paths",
-    "build:bundle:min": "./bin/build-bundle",
-    "build:bundle": "./bin/build-bundle && ./bin/build-bundle-locales",
-    "build:css": "bin/build-css",
-    "build:js": "npm run build:lib && npm run build:bundle && npm run build:bundle:min",
+    "build:js": "npm-run-all --parallel build:bundle build:lib",
     "build:lib": "babel --version && babel src -d lib",
-    "build": "npm run build:lib && npm run build:bundle && npm run build:bundle:min && npm run build:css",
+    "build": "npm-run-all --parallel new:build:js new:build:css",
     "clean": "rm -rf lib && rm -rf dist",
     "docs": "cd website && node node_modules/documentation/bin/documentation.js readme ../src/index.js --readme-file=src/api/docs.md --section 'Uppy Core & Plugins' -q --github -c doc-order.json",
     "install": "npm run web:install",
@@ -28,9 +28,9 @@
     "test": "npm run lint && npm run test:unit",
     "travis:deletecache": "travis cache --delete",
     "watch:css": "nodemon --watch src --ext scss -x 'npm run build:css && node website/update.js'",
-    "watch:fast": "parallelshell 'npm run watch:css' 'npm run web:preview'",
+    "watch:fast": "npm-run-all --parallel watch:css web:preview",
     "watch:js": "nodemon --watch src --ext js -x 'npm run build:bundle && node website/update.js'",
-    "watch": "parallelshell 'npm run watch:js' 'npm run watch:css' && node website/update.js",
+    "watch": "npm-run-all --parallel watch:js watch:css website/update.js",
     "web:build": "cd website && node update.js && ./node_modules/.bin/hexo generate --silent && node build-examples.js",
     "web:clean": "cd website && ./node_modules/.bin/hexo clean",
     "web:deploy": "npm run web:install && npm run web:disc && npm run docs && npm run web:build && ./bin/web-deploy",
@@ -38,7 +38,8 @@
     "web:install": "cd website && npm install",
     "web:preview": "cd website && parallelshell 'node build-examples.js watch' './node_modules/.bin/hexo server'",
     "web:update:frontpage:code:sample": "cd website && ./node_modules/.bin/hexo generate && cp -f public/frontpage-code-sample.html ./themes/uppy/layout/partials/frontpage-code-sample.html",
-    "web": "npm run web:clean && npm run web:build"
+    "web": "npm run web:clean && npm run web:build",
+    "prepublish": ""
   },
   "repository": {
     "type": "git",
@@ -51,6 +52,7 @@
   },
   "homepage": "https://github.com/transloadit/uppy#readme",
   "devDependencies": {
+    "autoprefixer": "6.3.6",
     "babel-cli": "6.6.5",
     "babel-core": "6.7.4",
     "babel-eslint": "6.0.2",
@@ -59,13 +61,14 @@
     "babel-plugin-transform-object-assign": "6.5.0",
     "babel-plugin-transform-proto-to-assign": "6.8.0",
     "babel-polyfill": "6.7.4",
-    "babel-preset-es2015": "6.6.0",
+    "babel-preset-es2015": "6.9.0",
     "babel-preset-es2015-loose": "7.0.0",
     "babel-register": "6.7.2",
     "babelify": "7.2.0",
     "browser-sync": "2.10.0",
     "browserify": "12.0.1",
     "chalk": "1.1.1",
+    "cssnano": "3.6.2",
     "disc": "1.3.2",
     "es6-promise": "3.1.2",
     "eslint": "2.7.0",
@@ -73,16 +76,19 @@
     "eslint-plugin-promise": "1.1.0",
     "eslint-plugin-standard": "1.3.2",
     "fakefile": "0.0.5",
+    "glob": "7.0.3",
     "isomorphic-fetch": "2.2.1",
+    "mkdirp": "0.5.1",
     "multi-glob": "1.0.1",
-    "nock": "^8.0.0",
-    "node-fetch": "^1.5.0",
+    "nock": "8.0.0",
+    "node-fetch": "1.5.0",
     "node-notifier": "4.4.0",
     "node-sass": "3.4.2",
     "nodemon": "1.8.1",
     "parallelshell": "2.0.0",
+    "postcss": "5.0.21",
     "selenium-webdriver": "2.52.0",
-    "tap-spec": "^4.1.1",
+    "tap-spec": "4.1.1",
     "tape": "4.4.0",
     "uppy-server": "0.0.7",
     "watchify": "3.6.1"
@@ -91,6 +97,6 @@
     "drag-drop": "2.11.0",
     "tus-js-client": "1.1.3",
     "whatwg-fetch": "1.0.0",
-    "yo-yo": "1.1.1"
+    "yo-yo": "1.2.0"
   }
 }