2015-09-16 58 views
2

我想要我的browserify版本需要代码imperavi's redactornpm package)。但我得到一个不可预知的错误。Browserify需要imperavi编码器

这是反应的元素

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']的代码。我得到一个错误:ReferenceError: RedactorPlugins is not definedredactor.js#L1430

但它们在table.js,这是redactor.js为什么我得到这个错误之前,需要定义。我怎样才能避免它,并开始成功使用redactor.js?

我试过很多东西:browserify-shim package,制作global.RedactorPlugins = {}等,但没有成功。

回答

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')) 
    });