2015-09-16 55 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')) 
    });