I'm working on an MVC React project on Visual Studio.
Everything so far has been fine, but now I have a typescript file I've written myself, which I want to be able to use in the project. It's something of a learning process for me, so for now I just want to be able to use that Typescript in a generic HTML page (not React) via standard <script src=...> tags.
I understand it needs to be compiled to JS, but I don't know how to set that process up.
I've found and tried a lot of solutions involving webpack.config.ts, package.json, tsconfig.json, etc, but nothing ever works.
Is there a definitive and obvious way to do this? Or is there something specific about my project that I've got wrong?
If it helps, here's how the file layout looks in my project (webGL.ts is the one I'm wanting to deal with).
I've tried adding this to tsconfig.json:
"files": [
"/ClientApp/webGL.ts"
]
My webpack.config.js file looks like this:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
entry: { 'main': './ClientApp/boot.tsx' },
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
module: {
rules: [
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{
//for reading font files
test: /\.(woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
}
]
},
plugins: [
new CheckerPlugin(),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('site.css')
])
}];
};
I suspect there's something I need to know or change in that file, but I'm a bit lost overall.
Any help much appreciated, thanks.
Update:
I also tried manually creating a JS file of the same name, with which I would manually copy TS into it and adjust as needed (I'm not actually trying to learn TS here, I'm trying to learn webGL and three.js, and would just prefer to do it via TS if I can).
After making the JS file, it was automatically placed as a stub under the TS file, like so:
I feel like this has some amount of relevance, but I don't know how or why. The fact that they've been automatically joined tells me something. I still don't know how to get it working in the project though..!

