Skip to content

Instantly share code, notes, and snippets.

@jrunestone
Last active June 12, 2024 03:23
Show Gist options
  • Select an option

  • Save jrunestone/2fbe5d6d5e425b7c046168b6d6e74e95 to your computer and use it in GitHub Desktop.

Select an option

Save jrunestone/2fbe5d6d5e425b7c046168b6d6e74e95 to your computer and use it in GitHub Desktop.

Revisions

  1. Johan Johansson revised this gist May 17, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion jquery-datatables-webpack
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Here's how to make jQuery DataTables work with npm and webpack. DT checks for AMD compatibility first which breaks everything when you're using CommonJS.
    Here's how to make jQuery DataTables work with npm and webpack. DT checks for AMD compatibility first
    which breaks when you're using CommonJS with webpack.

    Install DT core: npm install datatables.net
    Install a DT style: npm install datatables.net-bs (bootstrap)
  2. Johan Johansson revised this gist May 17, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jquery-datatables-webpack
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Here's how to make jQuery DataTables work with npm and webpack. DT checks for AMD compatibility first which breaks everything.
    Here's how to make jQuery DataTables work with npm and webpack. DT checks for AMD compatibility first which breaks everything when you're using CommonJS.

    Install DT core: npm install datatables.net
    Install a DT style: npm install datatables.net-bs (bootstrap)
  3. Johan Johansson created this gist May 17, 2016.
    25 changes: 25 additions & 0 deletions jquery-datatables-webpack
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    Here's how to make jQuery DataTables work with npm and webpack. DT checks for AMD compatibility first which breaks everything.

    Install DT core: npm install datatables.net
    Install a DT style: npm install datatables.net-bs (bootstrap)
    Install the imports-loader webpack plugin: https://github.com/webpack/imports-loader#disable-amd
    Create a loader "exception" just for DT in webpack.config.js:

    module: {
    loaders: [
    {
    test: /datatables\.net.*/,
    loader: 'imports?define=>false'
    }
    ]
    }

    Then to initialize DT in your app, do this in your main entry point:

    // you can use import or require
    import 'datatables.net';
    import dt from 'datatables.net-bs';
    dt(window, $);

    Now you can use .DataTable():
    $('table[data-table]').DataTable(); // or whatever you want