Note: I tested this with Webpack 2.2.1.
With Webpack you can use simple import ZoomCharts from './zoomcharts/zoomcharts.js';
and it works fine - including bundling of the zoomcharts.js
code.
Though in such case ZoomCharts will now load dependencies such as moment.js
by itself even if they are already included in the webpack bundle. To enable loading moment.js
from the bundle, I used this webpack.config.js
file (and using the imports-loader
plugin):
var path = require('path');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname)
},
resolve: {
alias: {
"moment": path.resolve(__dirname, "zoomcharts", "assets", "moment.js"),
"moment-timezone": path.resolve(__dirname, "zoomcharts", "assets", "moment-tz.js"),
"zoomcharts": path.resolve(__dirname, "zoomcharts", "zoomcharts.js"),
}
},
module: {
rules: [
{
test: path.resolve(__dirname, "zoomcharts", "zoomcharts.js"),
loader: {
loader: "imports-loader",
options: {
"moment": "moment",
"momentTimezone": "moment-timezone",
// workaround that sets window.moment as required by zoomcharts.js
"_": ">window.moment=moment;"
}
}
}
],
}
};