Here is an example of how I do this on my own site. I'm not sure if this is the only way or even the best way, but it is clean, simple and works for me.
Important noteworthy note . Use window["propName"] when declaring objects in a window, because when you run webpack -p it will carbonize any non-line lines, so if you define it as window.propName , it can be changed to something like sc , and the rest of your code does not know what it is. Declaring a character as a string as a string will cause webpack to keep the name intact so that you can access it from anywhere with the same name.
site.ts (maybe .js, doesn't matter)
declare var $:JQueryStatic; declare var jQuery:JQueryStatic; window["$"] = window["jQuery"] = require("jquery"); require("jquery-ui/effects/effect-slide"); require("jquery-ui/widgets/autocomplete"); require("jquery-ui/widgets/button"); require("jquery-ui/widgets/datepicker"); require("jquery-ui/widgets/tooltip"); declare var angular:ng.IAngularStatic; window["angular"] = require("angular"); require("angular-sanitize"); window["moment"] = require("moment"); window["saveAs"] = require("FileSaver").saveAs; window["JSZip"] = require("jszip"); declare var globals:Globals; window["globals"] = require("./globals");
Layout.html (loaded on every page)
..... <script src="/dist/scripts/site.bundle.js"></script> .....
webpack.config.js
var path = require('path'); var resolve = path.resolve; var AssetsPlugin = require('assets-webpack-plugin'); var WebpackCleanupPlugin = require("webpack-cleanup-plugin"); 'use strict'; var babelOptions = { "presets": [ [ "es2015", { "modules": false } ], "es2016" ] }; module.exports = [{ cache: true, context: resolve('Scripts'), devtool: "source-map", entry: { site: './site.ts', }, output: { path: path.resolve(__dirname, './dist/scripts'), filename: '[name].bundle.js', }, module: { rules: [{ test: /\.ts$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: babelOptions }, { loader: 'ts-loader' } ] }, { test: /\.js$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: babelOptions } ] }] }, plugins: [ new AssetsPlugin({ path: path.resolve(__dirname, './dist/assets') }), new WebpackCleanupPlugin({}) ], }];