I have 2 entry points: One for the main app, and one for legacy part of the app.
The legacy.js, is being bundled just as I want it to, like so:
module.exports = {
entry: {
app: ['file1', 'file2'],
legacy: ['legacyfile1', 'legacyfile2'],
},
devtool: 'source-map',
context: path.resolve(__dirname, 'src'),
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'js/[name].js'
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
chunks: ['app'] // Only include app bundle - Legacy will be required in the legacy javascript file.js at runtime.
}),
}
This generates the two bundles, and only the app.js bundle is injected into index.html.
Then inside legacy.js, I want to require the legacy bundle at the top of the file, something like this (all does not work, Webpack can not find the modules):
require('./dist/js/legacy.js');
require('./js/legacy.js');
require('dist/js/legacy.js');
require('/js/legacy.js');
How is it possible with Webpack to require a Webpack bundled file into a javascript file at runtime?
Thanks for those who find the time to consider this!