| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- const path = require("path");
- const TerserJSPlugin = require('terser-webpack-plugin');
- const HtmlPlugin = require("html-webpack-plugin");
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
- const { CleanWebpackPlugin } = require("clean-webpack-plugin");
- const OptimizeCSSAssetsPlugin = require('css-minimizer-webpack-plugin');
- const webpack = require("webpack");
- const ASSET_INLINE_LIMIT = 100000;
- const TERSER_PARALLEL_WORKERS = 4;
- const PROJECT_NAME_PATH_OFFSET = -1;
- /**
- * Gets the project name from the webpack configuration directory.
- *
- * @returns {string} The project directory name.
- * @sideEffects None.
- */
- function getCurrentProjectName() {
- const pathParts = __dirname.split(path.sep);
- return pathParts[pathParts.length + PROJECT_NAME_PATH_OFFSET];
- }
- module.exports = {
- stats: {
- errorDetails: true,
- },
- plugins: [
- new CleanWebpackPlugin(),
- new HtmlPlugin(
- {
- template: "./ui/frontend/errors_template.tpl",
- filename: path.resolve(__dirname, './ui/frontend/errors.tpl'),
- chunks: ["frontend"]
- }
- ),
- new HtmlPlugin(
- {
- template: "./ui/frontend/masterpage_template.tpl",
- filename: path.resolve(__dirname, './ui/frontend/masterpage.tpl'),
- chunks: ["frontend"]
- }
- ),
- new MiniCssExtractPlugin({ filename: "styles.[contenthash].css" }),
- new webpack.ProvidePlugin({
- $: 'jquery',
- jQuery: 'jquery',
- "window.jQuery": 'jquery'
- })
- ],
- module: {
- rules: [
- {
- test: /\.(css|scss)$/,
- use: [
- { loader: MiniCssExtractPlugin.loader },
- { loader: "css-loader" },
- { loader: "sass-loader" }
- ]
- },
- // Import various assets
- {
- test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/,
- use: [
- { loader: 'url-loader', options: `?limit=${ASSET_INLINE_LIMIT}` }
- ]
- }
- ]
- },
- optimization: {
- minimizer: [
- new TerserJSPlugin(
- { terserOptions: { output: { comments: false } }, parallel: TERSER_PARALLEL_WORKERS }
- ),
- new OptimizeCSSAssetsPlugin(
- { minimizerOptions: { preset: ['default', { discardComments: { removeAll: true } }] } }
- )
- ],
- },
- entry: {
- "frontend": "./ui/frontend/js/frontend.js"
- },
- output: {
- publicPath: '/' + getCurrentProjectName() + '/assets/frontend/',
- path: path.resolve(__dirname, "assets/frontend/"),
- filename: "[name].[contenthash].js"
- },
- };
|