3

I've downloaded a javascript + css + images library (dxhtml) and want to bundle it instead of hardcoding the script/css imports in the html. But the javascript is not a module (it doesn't do module.exports).

What is the best way to achieve this? Should I add the main file in the library to entry in webpack.config.js?

I'm successfully bundling all kinds of node modules, but I've tried to include local files with no success.

Berco Beute
  • 1,115
  • 15
  • 30

1 Answers1

1

I got this working by configuring webpack with a css-loader and an exports-loader.

CSS Loader

Follow webpack's official CSS loader steps: https://github.com/webpack/css-loader

JavaScript Exports Loader

In order to load the JavaScript, use exports-loader to specify which functions you want to export from the DHTMLX file. First, install exports-loader:

npm install --save-dev exports-loader

Next, specify the functions that you want exported from dhtmlx:

require('./dhtmlx/tree/codebase/dhtmlxtree.css');

var dhx = require('exports?' +
    'treeObject=dhtmlXTreeObject' +
    '!./dhtmlx/tree/codebase/dhtmlxtree.js');

var myTree = new dhx.treeObject('treeboxbox_tree', '100%', '100%', 0);
Caleb
  • 2,197
  • 3
  • 19
  • 31