I have a webpack-bundled TypeScript file which exports a function I need to use from global, e.g.:
// bundled.ts
import * as Excel from 'exceljs';
import { saveAs } from 'file-saver';
declare const $find: any;
export function configExport() {
$('#ExportToExcelBtn').click( async () => {
...
let dataItems = $find('ViewGrid').get_masterTableView().get_dataItems();
...
});
}
// notBundled.js
configExport(); // does not exist in global window object
I must not be reading the docs correctly or something, but I am having trouble getting the configExport
function exposed/exported/provided/whatever to window
. I have looked into export-loader
, expose-loader
, and ProvidePlugin
, but I am not getting a clear sense of what I should do here.
So far I have tried something like this in my webpack.config.js:
module: {
rules: [
{
test: require.resolve("./Module/js/dist/bundled.js"),
use: [{
loader: "expose-loader",
options: "bundledModuleCode",
}]
},
but neither configExport
nor bundledModuleCode
appear in window
like I would want.
- Is this use case even supported?
- How do I go about it?