Brand new to webpack, and I'm facing obstacles in merging MVC components with webpack AND typescript. Take a look at my code combinations below:
webpack.config.js:
var wbConfigEntries = {
"jqkendoMain": [
paths.appjs + "main.ts"
]
};
module.exports = {
devtool: 'source-map',
entry: wbConfigEntries,
target: 'web',
output: {
path: paths.dist,
publicPath: './',
filename: outputFile,
library: "[name]",
libraryTarget: "umd",
umdNamedDefine: true
},
....
main.ts:
import * as $ from 'jquery';
import * as bootstrap from 'bootstrap';
import '../node_modules/@progress/kendo-ui/js/kendo.web';
import '../node_modules/@progress/kendo-ui/js/kendo.aspnetmvc';
import '../node_modules/bootstrap/dist/css/bootstrap.css';
import '../node_modules/bootstrap/dist/css/bootstrap-theme.css';
import '../node_modules/font-awesome/css/font-awesome.css';
import '../node_modules/@progress/kendo-ui/css/web/kendo.common.css';
export default class Main {
private _name = '';
constructor(name: string) {
this._name = name;
}
TestFunc() {
console.log(this._name);
}
}
_layout.cshtml:
...
var mn = new jqkendoMain.Main('@WebpackMVC5App.Helpers.WebConfigSettings.RandomWebConfigValue');
mn.TestFunc();
...
I am aware that I am importing some unnecessary things in main.ts, but it's a test case for updating legacy code. My ultimate objective is to compile/bundle all the typescript, and then pass certain values from an MVC5 static class to the typescript. I want to be able to call some of the bundled functions FROM my .cshtml files, but I'm struggling with that. I keep getting errors like jqkendoMain is undefined, or jqkendoMain.Main is undefined. Any insights on what I might be overlooking?
The above snippets are just pieces of the code I'm experimenting with, you can find the complete code at https://github.com/vishnu4/WebpackMVC5 .