Files
dspace-angular/webpack/webpack.common.ts
Yura Bondarenko 29d8dd68f4 87968: Remove html-webpack-plugin
After updating to Angular 12, it causes ng serve to fail with
  Conflict: Multiple assets emit different content to the same filename index.html

Confirmed that the application still builds and runs properly without it.

This plugin isn't used by @angular-builders/custom-webpack since Angular 8 (see https://www.justjeb.com/post/customizing-angular-cli-build#viewer-51npg), this is just the first time it's actually causing problems for us.

Removed script-ext-html-webpack-plugin as well since that's an extension to html-webpack-plugin & can't run without it.
2022-04-08 17:57:15 +02:00

100 lines
2.7 KiB
TypeScript

import { globalCSSImports, projectRoot } from './helpers';
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const sass = require('sass');
export const copyWebpackOptions = {
patterns: [
{
from: path.join(__dirname, '..', 'node_modules', '@fortawesome', 'fontawesome-free', 'webfonts'),
to: path.join('assets', 'fonts'),
force: undefined
},
{
from: path.join(__dirname, '..', 'src', 'assets'),
to: 'assets',
},
{
// replace(/\\/g, '/') because glob patterns need forward slashes, even on windows:
// https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
from: path.join(__dirname, '..', 'src', 'themes', '*', 'assets', '**', '*').replace(/\\/g, '/'),
to: 'assets',
noErrorOnMissing: true,
transformPath(targetPath, absolutePath) {
// use [\/|\\] to match both POSIX and Windows separators
const matches = absolutePath.match(/.*[\/|\\]themes[\/|\\]([^\/|^\\]+)[\/|\\]assets[\/|\\](.+)$/);
if (matches) {
// matches[1] is the theme name
// matches[2] is the rest of the path relative to the assets folder
// e.g. themes/custom/assets/images/logo.png will end up in assets/custom/images/logo.png
return path.join('assets', matches[1], matches[2]);
}
},
},
{
from: path.join(__dirname, '..', 'src', 'robots.txt'),
to: 'robots.txt'
}
]
};
const SCSS_LOADERS = [
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
// sass >1.33 complains about deprecation warnings in Bootstrap 4
// After upgrading to Angular 12 we need to explicitly use an older version here
// todo: remove after upgrading to Bootstrap 5
implementation: sass,
sassOptions: {
includePaths: [projectRoot('./')]
}
}
},
];
export const commonExports = {
plugins: [
new CopyWebpackPlugin(copyWebpackOptions),
],
module: {
rules: [
{
test: /\.ts$/,
loader: '@ngtools/webpack'
},
{
test: /\.scss$/,
exclude: [
/node_modules/,
/(_exposed)?_variables.scss$|[\/|\\]src[\/|\\]themes[\/|\\].+?[\/|\\]styles[\/|\\].+\.scss$/
],
use: [
...SCSS_LOADERS,
{
loader: 'sass-resources-loader',
options: {
resources: globalCSSImports()
},
}
]
},
{
test: /(_exposed)?_variables.scss$|[\/|\\]src[\/|\\]themes[\/|\\].+?[\/|\\]styles[\/|\\].+\.scss$/,
exclude: [/node_modules/],
use: [
...SCSS_LOADERS,
]
},
],
},
};