jakiestfu / Medium.js

A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)

Home Page:http://jakiestfu.github.io/Medium.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Browserify + Medium.js

aeneasr opened this issue · comments

It took me quite some time to get Medium.js (with invokables) working with Browserify and React. The reason is, that Medium.js (as it seems) requires Undo and rangy to get invokables working. However, it gets these dependencies by doying:

            rangy = w['rangy'] || null,
            undo = w['Undo'] || null,
            wild = (!rangy || !undo),

where w is window:

(function (w, d) {
    'use strict';
`}).call(this, window, document);

so when using Browserify, Medium.js does not correctly resolve the dependencies, which causes invokables to be broken.

To fix this, one has to load the dependencies via require BEFORE he first loads Medium.js and bind them to window:

window.rangy = require('rangy');
window.Undo = require('undo.js');
require('rangy/lib/rangy-classapplier.js'); // not 100% sure if this is needed

var React = require('react'),
    Medium = require('Medium.js'),
    _ = require('underscore');

This is obviously a pretty bad workflow. Maybe I'm doing something wrong, but it looks like the npm integration needs some work.

Looks related to #105