feat: Add module support with new dist files

- `/dist/color-thief.umd.js`: UMD module. For simple script tag loading that exposes a global variable or for RequireJS AMD support.
- `/dist/color-thief.js`: CommonJS module. Entry point for Node.js and Browserify.
- `/dist/color-thief.mjs`: ES6 module. For modern browsers as well as Webpack and Rollup.
- `/dist/color-thief.min.js`: Duplicate of `/dist/color-thief.umd.js`. Kept around to maintain backwards compatibility.
This commit is contained in:
Lokesh Dhakar
2019-07-14 20:00:27 -07:00
parent 2708113d10
commit c91f3e808e
20 changed files with 5659 additions and 1003 deletions

View File

@@ -1,20 +1,23 @@
const minify = require('@node-minify/core');
const uglify = require('@node-minify/uglify-es');
var fs = require('fs');
const { resolve } = require('path');
minify({
compressor: uglify,
input: './src/color-thief.js',
output: './dist/color-thief.min.js',
options: {
output: {
comments: 'some'
}
},
callback: function(err, min) {
if (err) {
console.log('⚠ERROR:' + err);
} else {
console.log('✅ Minification completed');
}
}
/*
color-thief.umd.js duplicated as color-thief.min.js for legacy support
In Color Thief v2.1 <= there was one distribution file (dist/color-thief.min.js)
and it exposed a global variable ColorThief. Starting from v2.2, the package
includes multiple dist files for the various module systems. One of these is
the UMD format which falls back to a global variable if the requirejs AMD format
is not being used. This file is called color-thief.umd.js in the dist folder. We
want to keep supporting the previous users who were loading
dist/color-thief.min.js and expecting a global var. For this reason we're
duplicating the UMD compatible file and giving it that name.
*/
const source = resolve(process.cwd(), 'dist/color-thief.umd.js');
const dest = resolve(process.cwd(), 'dist/color-thief.min.js');
fs.copyFile(source, dest, (err) => {
if (err) throw err;
console.log('source.txt was copied to destination.txt');
});