forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.common.ts
More file actions
137 lines (133 loc) · 4.23 KB
/
webpack.common.ts
File metadata and controls
137 lines (133 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { globalCSSImports, projectRoot, getFileHashes, calculateFileHash } from './helpers';
import { EnvironmentPlugin } from 'webpack';
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const sass = require('sass');
const JSON5 = require('json5');
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', '**', '*.json5').replace(/\\/g, '/'),
to({ absoluteFilename }) {
// use [\/|\\] to match both POSIX and Windows separators
const matches = absoluteFilename.match(/.*[\/|\\]assets[\/|\\](.+)\.json5$/);
if (matches) {
const fileHash: string = process.env.NODE_ENV === 'production' ? `.${calculateFileHash(absoluteFilename)}` : '';
// matches[1] is the relative path from src/assets to the JSON5 file, without the extension
return path.join('assets', `${matches[1]}${fileHash}.json`);
}
},
transform(content) {
return JSON.stringify(JSON5.parse(content.toString()));
}
},
{
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, '/'),
noErrorOnMissing: true,
to({ absoluteFilename }) {
// use [\/|\\] to match both POSIX and Windows separators
const matches = absoluteFilename.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.ejs'),
to: 'assets/robots.txt.ejs'
},
{
from: path.join(__dirname, '..', 'src', 'aai', 'aai.js'),
to: 'aai.js'
},
{
from: path.join(__dirname, '..', 'src', 'aai', 'aai_config.js'),
to: 'aai_config.js'
},
{
from: path.join(__dirname, '..', 'src', 'aai', 'discojuice', 'discojuice.js'),
to: 'discojuice.js'
},
{
from: path.join(__dirname, '..', 'src', 'static-files'),
to: 'static-files'
}
]
};
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 EnvironmentPlugin({
languageHashes: getFileHashes(path.join(__dirname, '..', 'src', 'assets', 'i18n'), /.*\.json5/g),
}),
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,
]
},
],
},
ignoreWarnings: [
/src\/themes\/[^/]+\/.*theme.module.ts is part of the TypeScript compilation but it's unused/,
]
};