ruhley / angular-color-picker

Vanilla AngularJS Color Picker Directive with no requirement on jQuery
http://ruhley.github.io/angular-color-picker/
MIT License
165 stars 78 forks source link

Support for Webpack + CommonJS Package Manager #22

Closed benoror closed 9 years ago

benoror commented 9 years ago

Motivation

Hi!

I'm in the process of refactoring an app to support modern JS tooling like NPM-only, Webpack & ES6.

Code Change

A small change is needed to support CommonJS.

/* commonjs package manager support (eg componentjs) */
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){
  module.exports = 'angular-md5';
}

I have done other PRs for some of my dependencies:

benoror commented 9 years ago

I have successfully added CommonJS support to this module :smile: https://github.com/benoror/angular-color-picker/commit/2142f4129c5222a7406934b98ec4add9d599bc31

I can do this now:

import colorpicker from 'angular-color-picker/angularjs-color-picker.js';
import 'angular-color-picker/angularjs-color-picker.css';
/** ... **/
export default angular.module('app.xyz', [
    colorpicker 
  ])
  .name;

But ... unfortunately I have issues with TinyColor, since it places the tinycolor function in the global scope

benoror commented 9 years ago

Got it! I had to shim the module with imports-loader:

import tinycolor from 'tinycolor2';
import colorpicker from 'imports?tinycolor=tinycolor2!angular-color-picker/angularjs-color-picker.js';
import 'angular-color-picker/angularjs-color-picker.css';

*Source: http://webpack.github.io/docs/shimming-modules.html#imports-loader