'use strict'; const path = require('path'); const webpack = require('webpack'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const TerserPlugin = require('terser-webpack-plugin'); const Dotenv = require('dotenv-webpack'); const {config} = require('dotenv') const { container: {ModuleFederationPlugin} } = webpack; const {normalizeCssPaths} = require("./normalize-css-path"); function _path(p) { return path.join(__dirname, p); } config(); module.exports = { mode: 'production', entry: { polyfills: './build/scripts/polyfills.js', vendor: './build/scripts/vendor.js', main: './build/scripts/main.aot.js', }, context: process.cwd(), output: { path: path.join(process.cwd(), './dist'), filename: '[name].[chunkhash].bundle.js', chunkFilename: '[id].[chunkhash].chunk.js', assetModuleFilename: 'src/resources/[base]', publicPath: 'auto' }, module: { rules: [ { test: /\.js$/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } }, { test: /\.js$/, use: { loader: 'angular-router-loader?aot=true' } }, { test: /\.html$/, use: { loader: 'raw-loader' } }, { test: /\.css$/, use: [ { loader: MiniCssExtractPlugin.loader, options: { // you can specify a publicPath here // by default it use publicPath in webpackOptions.output // publicPath: '../' } }, { loader: 'css-loader' } ] }, { test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf)$/, type: 'asset/resource' } ] }, optimization: { minimizer: [ new TerserPlugin({ parallel: true, terserOptions: { // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions } }) ], splitChunks: { // include all types of chunks chunks: 'all' } }, plugins: [ new Dotenv(), () => normalizeCssPaths({ paths: [ './build/resources/css/font-faces.css.shim.ngstyle.js', './build/resources/css/style.css.ngstyle.js' ], outDir: `${process.env.MFE_BASE_URL || ''}/src/resources`, }), // new BundleAnalyzerPlugin(), new HtmlWebpackPlugin({ template: 'index.webpack.html', filename: 'index.html', chunksSortMode: 'none' }), new CopyWebpackPlugin([ {from: 'index.webpack.html', to: 'index.html'}, {from: 'src/resources/img/progress.gif', to: 'src/resources/img/progress.gif'}, {from: 'src/resources/img/logo.png', to: 'src/resources/img/logo.png'}, {from: 'src/resources/app-config.json', to: 'src/resources/app-config.json'}, {from: 'src/resources/app.version', to: 'src/resources/app.version'} ]), new MiniCssExtractPlugin({ filename: '[name].[fullhash].css', chunkFilename: '[id].[fullhash].css' }), new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", "window.jQuery": "jquery", Popper: ['popper.js', 'default'] }), new ModuleFederationPlugin({ name: 'dashboard', filename: 'remoteEntry.js', exposes: { "./dashboard": "./build/scripts/mfe-main.aot", }, }) ], resolve: { alias: { 'jquery': _path('node_modules/jquery/dist/jquery.min'), 'inputmask': _path('node_modules/inputmask/dist/inputmask'), 'downloadjs': _path('node_modules/downloadjs/download.min.js'), 'esmarttokenjs': _path('node_modules/esmarttokenjs/esmarttoken.js'), 'cadesplugin_api': _path('node_modules/cadesplugin_api/index.js'), 'eonasdan-bootstrap-datetimepicker': _path('node_modules/eonasdan-bootstrap-datetimepicker/src/js/bootstrap-datetimepicker'), 'autonumeric': _path('node_modules/autonumeric/dist/autoNumeric.js'), 'jsgantt-improved': _path('node_modules/jsgantt-improved/dist/jsgantt.js'), 'js-year-calendar': _path('node_modules/js-year-calendar/dist/js-year-calendar.js'), 'chart.js': _path('node_modules/chart.js/dist/chart.js') }, modules: [ 'node_modules', path.resolve(process.cwd(), './build'), path.resolve(process.cwd(), './build/scripts'), ], extensions: ['.js'] }, stats: { children: false }, devtool: false };