Browserify需要imperavi编辑器

时间:2015-09-16 12:01:56

标签: javascript coffeescript reactjs browserify redactor

我想要将imperavi's redactornpm package)的代码添加到我的browserify构建中。但是我得到了一个不可预测的错误。

这是react元素的代码

React = require('react')
ReactBootstrap = require('react-bootstrap')

Input = ReactBootstrap.Input
Button = ReactBootstrap.Button

require('bower-redactor/redactor/redactor-plugins/table.js')
require('bower-redactor/redactor/redactor.js')
require('bower-redactor/redactor/langs/ru.js')

module.exports = React.createClass
  componentDidMount: ->
    jQuery('textarea.redactor').redactor
      lang: 'ru'
      plugins: ['table']
  render: ->
    <form>
      ...
      <Input type='textarea' ref='content' className='redactor' defaultValue={@props.content} />
      ...
    </form>

一切顺利,直到require('bower-redactor/redactor/redactor-plugins/table.js')并将plugins: ['table']添加到代码中。我在redactor.js#L1430

收到错误:ReferenceError: RedactorPlugins is not defined

但它们是在table.js定义的,这在redactor.js之前是必需的。为什么我会收到此错误。如何避免它并开始成功使用redactor.js?

我尝试了很多事情:browserify-shim package,制作global.RedactorPlugins = {}等等,但没有成功。

1 个答案:

答案 0 :(得分:3)

您需要在捆绑包中包含代码。它将是全球性的,因此您只需参考它。要求不起作用。有了吞咽,看起来就像这样;

    var source = {
        libjs: ['bower-redactor/redactor/redactor-plugins/table.js', 'bower-redactor/redactor/redactor.js', 'bower-redactor/redactor/langs/ru.js']
    };

    gulp.task('libjs', function () {
        gulp.src(source.libjs)
            .pipe(concat('lib.min.js'))
            .pipe(gulp.dest('./ui-dist'))
    });