As in the question, is it possible?
This is my webpack.config.js
:
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const generateHtmlPlugin = (chunks, filename, inject, template, templateParameters) => {
return new HtmlWebpackPlugin({
chunks,
filename,
inject,
template,
templateParameters
});
}
const multipleModulesTemplatesArray = [
{
filename: 'egm_mm_wrapper_bottom_banner.html',
inject: 'head',
template: 'src/html/template.ejs',
templateParameters: {
bodyClass: 'egm_mm_wrapper_bottom_banner',
htmlClass: 'egm_mm_wrapper_bottom_banner',
initConsoleLog: 'MMWrapperBottom start'
}
},
{
filename: 'egm_mm_wrapper_overhead_display.html',
inject: 'head',
template: 'src/html/template.ejs',
templateParameters: {
bodyClass: 'egm_mm_wrapper_overhead_display',
htmlClass: 'egm_mm_wrapper_overhead_display',
initConsoleLog: 'MMWrapperOverhead start'
}
},
{
filename: 'ilink_media_scheduler.html',
inject: 'head',
template: 'src/html/template.ejs',
templateParameters: {
bodyClass: 'ilink_media_scheduler',
htmlClass: 'ilink_media_scheduler',
initConsoleLog: 'WMiLink.MediaScheduler start'
}
},
{
filename: 'ilink_window_manager.html',
inject: 'head',
template: 'src/html/template.ejs',
templateParameters: {
bodyClass: 'ilink_window_manager',
htmlClass: 'ilink_window_manager',
initConsoleLog: 'WMiLink.WindowManager start'
}
}
];
const populateHtmlPlugins = (pagesArray) => {
const result = [];
pagesArray.forEach(page => {
result.push(generateHtmlPlugin(page.chunks, page.filename, page.inject, page.template, page.templateParameters));
})
return result;
}
const templates = populateHtmlPlugins(multipleModulesTemplatesArray);
const commonsAndVendorsConfig = {
context: path.resolve(__dirname, '.'),
devServer: {
client: {
logging: 'verbose',
overlay: true,
},
static: {
directory: path.join(__dirname, './dist'),
},
compress: true,
port: 9001,
},
entry: [
'../shared_libs/modules/vendors.js',
'../shared_libs/modules/commons.js',
'./src/js/egm_mm_wrapper_commons.js',
'./src/js/ilink_commons.js',
],
mode: 'production',
module: {
rules: [
{
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env'
]
},
test: /.js$/
}
]
},
name: 'commons-and-vendors',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
ecma: 5,
format: {
comments: false,
},
mangle: {
toplevel: true
},
module: true
},
}),
]
},
output: {
filename: 'commons_and_vendors.[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
target: 'web'
};
const multipleModulesConfig = {
context: path.resolve(__dirname, '.'),
dependencies: ['commons-and-vendors'],
devServer: {
client: {
logging: 'verbose',
overlay: true,
},
static: {
directory: path.join(__dirname, './dist'),
},
compress: true,
port: 9001,
},
entry: {
egm_mm_wrapper_bottom_banner: './modules/egm_mm_wrapper_bottom_banner.js',
egm_mm_wrapper_overhead_display: './modules/egm_mm_wrapper_overhead_display.js',
ilink_media_scheduler: './modules/ilink_media_scheduler.js',
ilink_window_manager: './modules/ilink_window_manager.js'
},
mode: 'production',
module: {
rules: [
{
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env']
]
},
test: /.js$/
},
{
exclude: /node_modules/,
test: /.s[ac]ss$/i,
use: [
'css-loader',
'sass-loader'
]
},
{
test: /.html$/i,
loader: 'html-loader',
options: {
minimize: true
},
},
]
},
name: 'multiple-modules',
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin({
test: /.s[ac]ss$/i
}),
new TerserPlugin({
extractComments: false,
terserOptions: {
ecma: 5,
format: {
comments: false,
},
mangle: {
toplevel: true
},
module: true
},
}),
]
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
plugins: templates,
target: 'web'
};
const singleModuleConfig = {
context: path.resolve(__dirname, '.'),
dependencies: ['multiple-modules'],
devServer: {
client: {
logging: 'verbose',
overlay: true,
},
static: {
directory: path.join(__dirname, './dist'),
},
compress: true,
port: 9001,
},
entry: './modules/mma.js',
mode: 'production',
module: {
rules: [
{
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env']
]
},
test: /.js$/
},
{
exclude: /node_modules/,
loader: 'html-loader',
options: {
minimize: true
},
test: /.html$/
},
]
},
name: 'mma',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
ecma: 5,
format: {
comments: false,
},
mangle: {
toplevel: true
},
module: true
},
}),
]
},
output: {
clean: true,
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
target: 'web'
};
module.exports = [commonsAndVendorsConfig, multipleModulesConfig, singleModuleConfig];
module.exports.parallelism = 1;
This is my template.ejs
file:
<html class="<%= htmlClass %>">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Window Manager</title>
<script type='application/javascript'>
console.log('<%= initConsoleLog %>');
</script>
</head>
<body class="<%= bodyClass %>">
<div class="mmContentContainer"></div>
</body>
</html>
And here’s my mma.js
file:
import '../dist/commons_and_vendors';
import '../dist/egm_mm_wrapper_bottom_banner';
import '../dist/egm_mm_wrapper_overhead_display';
import '../dist/ilink_media_scheduler';
import '../dist/ilink_window_manager';
import egm_mm_wrapper_bottom_banner from '../dist/egm_mm_wrapper_bottom_banner.html';
import egm_mm_wrapper_overhead_display from '../dist/egm_mm_wrapper_overhead_display.html';
import ilink_media_scheduler from '../dist/ilink_media_scheduler.html';
import ilink_window_manager from '../dist/ilink_window_manager.html';
And when I run the webpack build, I get the error:
ERROR in ./modules/mma.js 47:0-37
Module not found: Error: Can't resolve '../dist/commons_and_vendors' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 48:0-46
Module not found: Error: Can't resolve '../dist/egm_mm_wrapper_bottom_banner' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 49:0-49
Module not found: Error: Can't resolve '../dist/egm_mm_wrapper_overhead_display' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 50:0-39
Module not found: Error: Can't resolve '../dist/ilink_media_scheduler' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 51:0-38
Module not found: Error: Can't resolve '../dist/ilink_window_manager' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 52:0-85
Module not found: Error: Can't resolve '../dist/egm_mm_wrapper_bottom_banner.html' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 53:0-91
Module not found: Error: Can't resolve '../dist/egm_mm_wrapper_overhead_display.html' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 54:0-71
Module not found: Error: Can't resolve '../dist/ilink_media_scheduler.html' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
ERROR in ./modules/mma.js 55:0-69
Module not found: Error: Can't resolve '../dist/ilink_window_manager.html' in 'C:UsersuserProjectsmultimedia_advertisementmodules'
9 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
When I run webpack build with the above suggested flag --stats-error-details
, I get among other errors such an error:
Module not found: Error: Can't resolve '../dist/egm_mm_wrapper_overhead_display.html' in 'C:UsersuserProjectmultimedia_advertisementmodules'
resolve '../dist/egm_mm_wrapper_overhead_display.html' in 'C:UsersuserProjectmultimedia_advertisementmodules'
using description file: C:UsersuserProjectmultimedia_advertisementpackage.json (relative path: ./modules)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:UsersuserProjectmultimedia_advertisementpackage.json (relative path: ./dist/egm_mm_wrapper_overhead_display.html)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:UsersuserProjectmultimedia_advertisementdistegm_mm_wrapper_overhead_display.html doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:UsersuserProjectmultimedia_advertisementdistegm_mm_wrapper_overhead_display.html.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:UsersuserProjectmultimedia_advertisementdistegm_mm_wrapper_overhead_display.html.json doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
C:UsersuserProjectmultimedia_advertisementdistegm_mm_wrapper_overhead_display.html.wasm doesn't exist
as directory
C:UsersuserProjectmultimedia_advertisementdistegm_mm_wrapper_overhead_display.html doesn't exist
Even adding the module.exports.parallelism = 1;
doesn’t help.
On the side note, in error messsage we can see something like ERROR in ./modules/mma.js 50:0-39
, the line number is such, because I have commented code before the current used code.
If I delete it and put in the mma.js
file only the needed code, the same errors persist.
Did anyone stumbled upon potential solution regarding sequential code running?