const fs = require('fs'); const path = require('path'); const TerserPlugin = require('terser-webpack-plugin'); const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin'); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin'); const ESLintPlugin = require('eslint-webpack-plugin'); const isDevelopment = process.env.NODE_ENV !== 'production'; const includePaths = require('rollup-plugin-includepaths')(); const multiEntry = require('rollup-plugin-multi-entry')(); const buble = require('rollup-plugin-buble')({ transforms: { dangerousForOf: true } }); const typescript = require('@rollup/plugin-typescript')(); let plugins = [ new IgnoreEmitPlugin(/css\/.*(? name.match(/([-a-z]+).scss/)[1] ); const themes = {}; for (const name of themeNames) { themes[`css/${name}`] = `./css/themes/${name}.scss`; } module.exports = { mode: isDevelopment ? 'development' : 'production', entry: { 'js/app.js': './js/app.js', 'js/worker.js': './js/sw/worker.ts', ...themes }, output: { filename: '[name]', path: path.resolve(__dirname, '../priv/static'), }, optimization: { minimize: !isDevelopment, providedExports: true, usedExports: true, concatenateModules: true, }, devtool: isDevelopment ? 'inline-source-map' : undefined, performance: { hints: false }, resolve: { alias: { common: path.resolve(__dirname, 'css/common/'), views: path.resolve(__dirname, 'css/views/') } }, module: { rules: [ { test: /\.(ttf|eot|svg|woff2?)$/, loader: 'file-loader', options: { name: '[name].[ext]', outputPath: './fonts', publicPath: '../fonts', }, }, { test: /(app\.js|worker\.ts)/, use: [ { loader: 'webpack-rollup-loader', options: { plugins: [ buble, includePaths, multiEntry, typescript, ] } }, ], }, { test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { sourceMap: isDevelopment, url: (url) => !url.startsWith('/'), }, }, { loader: 'postcss-loader', options: { postcssOptions: { sourceMaps: isDevelopment, ident: 'postcss', syntax: 'postcss-scss', plugins: [ require('autoprefixer')(), ], }, }, }, { loader: 'sass-loader', options: { sourceMap: isDevelopment, sassOptions: { quietDeps: true } } }, ] }, ], }, plugins, };