2015-10-06 48 views
0

我有这个browserify垫片配置:Browserify和jQuery数据表扩展

"browser": { 
    "jquery": "./node_modules/jquery/dist/jquery.js", 
    "bootstrap": "./node_modules/bootstrap/dist/js/bootstrap.js", 
    "datatables": "./node_modules/datatables/media/js/jquery.dataTables.js", 
    "dt-bootstrap": "./source/vendors/js/dataTables.bootstrap.js", 
    "dt-select": "./source/vendors/js/dataTables.select.js" 
    }, 
    "browserify": { 
    "transform": [ 
     "browserify-shim" 
    ] 
    }, 
    "browserify-shim": { 
    "jquery": "$", 
    "bootstrap": { 
     "depends": [ 
     "jquery:jQuery" 
     ] 
    }, 
    "datatables": { 
     "exports": "DataTable", 
     "depends": [ 
     "jquery:$" 
     ] 
    }, 
    "dt-bootstrap": { 
     "depends": ["jquery:$", "datatables:DataTable"] 
    }, 
    "dt-select": { 
     "depends": ["jquery:jquery", "datatables:DataTable"] 
    } 
    }, 

,当我尝试到:

import dtBootstrap from 'dt-bootstrap' 

后browserify它给浏览器提供了错误:

Uncaught Error: Cannot find module 'jquery' 

只有当我尝试时才会出现此错误:

import $ from 'jquery' 
import bootstrap from 'bootstrap' 
import DataTable from 'datatables' 

// Include any of this modules gives error. 
import dtBootstrap from 'dt-bootstrap' 
import dtSelect from 'dt-select' 

当我不使用他们,只使用,这一切都会好起来:

import $ from 'jquery' 
import bootstrap from 'bootstrap' 
import DataTable from 'datatables' 

// No include no error. 
//import dtBootstrap from 'dt-bootstrap' 
//import dtSelect from 'dt-select' 

他们使用从数据表LIB工厂模式。

任何人有想法我做错了什么? 我尝试了许多配置来包含DataTables扩展的依赖关系。

回答

0

我已经从datatables site external datatables.js文件生成并将其包含到供应商中。 然后在我的browserify-shim配置中使用它。而所有的工作!

"browser": { 
    "jquery": "./node_modules/jquery/dist/jquery.js", 
    "bootstrap": "./node_modules/bootstrap/dist/js/bootstrap.js", 
    "datatables": "./source/vendors/js/datatables.js" 
    }, 
    "browserify": { 
    "transform": [ 
     "browserify-shim" 
    ] 
    }, 
"browserify-shim": { 
    "jquery": "$", 
    "bootstrap": { 
    "depends": [ 
    "jquery:jQuery" 
    ] 
    }, 
"datatables": { 
    "exports": "DataTable", 
    "depends": [ 
    "jquery:$" 
    ] 
} 
},