-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
125 lines (122 loc) · 3.9 KB
/
webpack.common.js
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
import fs from 'fs/promises';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import SvgChunkWebpackPlugin from 'svg-chunk-webpack-plugin';
import paths from './webpack.paths.js';
import semver from 'semver';
import packageJson from './package.json' assert { type: 'json' };
if (!semver.satisfies(process.version, packageJson.engines.node)) {
throw new Error(`The current Node.js version (${process.version}) does not satisfy the required version (${packageJson.engines.node}).`);
}
export default {
// Entry
entry: {
"bootstrap-italia": [paths.src + '/js/index.js', paths.src + '/scss/theme.scss'],
"ckeditor5": paths.src + '/scss/ckeditor5.scss',
"fonts": paths.src + '/scss/_fonts.scss',
"search-api--submit-filters": [paths.src + '/js/custom/search-api--submit-filters.js'],
"toc_js_loader": [paths.src + '/js/custom/toc_js.js'],
},
// Output
output: {
path: paths.build,
filename: "js/[name].min.js",
},
module: {
rules: [
{
test: /\.svg$/,
include: [
paths.modules + '/bootstrap-italia/src/svg',
//paths.modules + '/design-scuole-pagine-statiche/src/assets/icons',
paths.src + '/icons',
paths.src + '/svg',
paths.modules + '/design-scuole-pagine-statiche/src/assets/img'
],
use: [
{
loader: SvgChunkWebpackPlugin.loader,
},
],
},
// Uncomment if you use loading fonts vi CSS https://git.drupalcode.org/project/bootstrap_italia#loading-fonts-via-css-advanced-users
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
include: [
paths.modules + '/bootstrap-italia/src/fonts',
],
type: 'asset/resource',
generator: {
filename: 'fonts/[name]/[name][ext]',
},
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].min.css',
chunkFilename: 'css/[id].min.css'
}),
new SvgChunkWebpackPlugin({
filename: 'svg/sprites.svg',
svgstoreConfig: {
svgAttrs: {
'xmlns': 'http://www.w3.org/2000/svg',
}
}
}),
new CopyWebpackPlugin({
patterns: [
{
from: paths.modules + '/bootstrap-italia/src/assets/',
to: paths.build + '/assets/'
},
// Lascia commentato per non duplicare i fonts nella cartella dist
// {
// from: paths.modules + '/bootstrap-italia/src/fonts/',
// to: paths.build + '/fonts/'
// },
{
from: './src/images/',
to: paths.build + '/images/'
},
{
from: paths.modules + '/design-scuole-pagine-statiche/src/assets/css/ajax-loader.gif',
to: paths.build + '/css/ajax-loader.gif'
},
{
from: paths.modules + '/design-scuole-pagine-statiche/src/assets/css/images/',
to: paths.build + '/css/images/'
},
{
from: paths.modules + '/design-scuole-pagine-statiche/src/assets/img/',
to: paths.build + '/img/'
},
{
from: paths.modules + '/design-scuole-pagine-statiche/src/assets/placeholders/',
to: paths.build + '/placeholders/'
},
{
from: paths.modules + '/design-scuole-pagine-statiche/src/assets/svg/',
to: paths.build + '/svg/'
},
{
from: './version.css',
to: paths.build + '/css/version.css'
}
]
}),
{
apply: (compiler) => {
compiler.hooks.afterEmit.tapPromise('AfterEmitPlugin', async (compilation) => {
const ckeditorJsFile = `${compiler.options.output.path}/js/ckeditor5.min.js`;
try {
await fs.rm(ckeditorJsFile, { force: true });
} catch (err) {
console.error('Error deleting ckeditor5.min.js:', err);
}
});
},
},
],
};