简体   繁体   English

Browserify DataTables

[英]Browserify DataTables

I tried following the instructions at NPM packages - DataTables but I still can't get it to bundle with Browserify. 我尝试按照NPM包中的说明- DataTables但我仍然无法将其与Browserify捆绑在一起。

Here is my minimal, complete, and verifiable example: 这是我最小,完整,可验证的例子:

app.js app.js

'use strict'

var $ = require('jquery')
var dt = require('datatables.net-dt')()

$(document.getElementById('table')).DataTable()

Output of npm list 输出npm list

foo@1.0.0 /home/RinkAttendant6/www/foo
├─┬ datatables.net@1.10.10
│ └── jquery@2.1.4
└── datatables.net-dt@1.5.2

Output of browserify app.js -o bundle.js 输出browserify app.js -o bundle.js

Error: Cannot find module 'datatables.net-dt' from '/home/RinkAttendant6/www/foo'
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

What am I doing wrong? 我究竟做错了什么?

According to the package vendor, the datatables.net package should be used instead of datatables.net-dt unless Bootstrap or Foundation is used. 根据软件包供应商的说法,除非使用Bootstrap或Foundation,否则应使用datatables.net软件包而不是datatables.net-dt

Refer to https://github.com/DataTables/DataTables/issues/434#issuecomment-161278064 请参阅https://github.com/DataTables/DataTables/issues/434#issuecomment-161278064

Instead use: 而是使用:

 var dt = require('datatables.net')() 

The reason for this is that the datatables.net-dt package does not contain a Javascript file - it doesn't need one - it contains only CSS (it should actually contain a couple of images as well, that will be corrected in 1.10.11). 原因是datatables.net-dt包不包含Javascript文件 - 它不需要一个 - 它只包含CSS(它实际上应该包含几个图像,将在1.10中更正)。 11)。

No Javascript file is required there since the DataTables defaults are suitable for DataTables styling. 由于DataTables默认值适用于DataTables样式,因此不需要Javascript文件。 The same is not the case for Bootstrap, etc. Bootstrap等也不是这样。

Using another recommendation within that github issue thread worked for me. 使用该github问题线程中的另一个建议为我工作。

See: https://github.com/DataTables/DataTables/issues/434#issuecomment-113286718 请参阅: https//github.com/DataTables/DataTables/issues/434#issuecomment-113286718

var DataTable = require('datatables.net')()

$.fn.DataTable = DataTable

That code worked with or without a browserify-shim entry for datatables. 该代码使用或不使用browserify-shim数据表条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM