jakiestfu / Medium.js

A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)
http://jakiestfu.github.io/Medium.js/
4.39k stars 404 forks source link

Browserify + Medium.js #163

Open aeneasr opened 8 years ago

aeneasr commented 8 years ago

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.

dbackeus commented 8 years ago

Looks related to https://github.com/jakiestfu/Medium.js/pull/105