@massimo-cassandro/minimo 1.21.8 → 1.21.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev-tools/starter-kit/starter-install.sh +84 -27
- package/dev-tools/starter-kit/templates/__project__.code-workspace +2 -1
- package/dev-tools/starter-kit/templates/jsconfig.json +9 -8
- package/dev-tools/starter-kit/templates/package-tpl.json +3 -3
- package/dev-tools/starter-kit/webpack-template.ejs +5 -4
- package/dev-tools/starter-kit/webpack.config.mjs +40 -117
- package/package.json +1 -1
|
@@ -19,11 +19,16 @@ if [ -z "$ZSH_VERSION" ]; then
|
|
|
19
19
|
fi
|
|
20
20
|
|
|
21
21
|
# --no-npm: salta le installazioni npm (utile per testare rapidamente lo script)
|
|
22
|
+
# --root / --frontend: posizione della configurazione frontend (salta il prompt,
|
|
23
|
+
# utile per esecuzioni non interattive)
|
|
22
24
|
SKIP_NPM=0
|
|
25
|
+
FRONTEND_CHOICE=""
|
|
23
26
|
for ARG in "$@"; do
|
|
24
|
-
|
|
25
|
-
SKIP_NPM=1
|
|
26
|
-
|
|
27
|
+
case "$ARG" in
|
|
28
|
+
--no-npm) SKIP_NPM=1 ;;
|
|
29
|
+
--root) FRONTEND_CHOICE=1 ;;
|
|
30
|
+
--frontend) FRONTEND_CHOICE=2 ;;
|
|
31
|
+
esac
|
|
27
32
|
done
|
|
28
33
|
|
|
29
34
|
# Wrapper: esegue "npm i ..." a meno che SKIP_NPM sia attivo
|
|
@@ -105,11 +110,15 @@ fi
|
|
|
105
110
|
echo -e "${GREEN}...gitignore${NC}"
|
|
106
111
|
safe_cat "${TEMPLATES_DIR}/_gitignore" .gitignore new
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
if [ -n "$FRONTEND_CHOICE" ]; then
|
|
114
|
+
choice="$FRONTEND_CHOICE"
|
|
115
|
+
else
|
|
116
|
+
echo -e "\n${GREEN}Where do you want to install the frontend configuration?${NC}"
|
|
117
|
+
echo "1) Root directory"
|
|
118
|
+
echo "2) 'frontend' Directory"
|
|
119
|
+
read "?Choose (1 or 2) [default: 1]: " choice < /dev/tty
|
|
120
|
+
choice=${choice:-1}
|
|
121
|
+
fi
|
|
113
122
|
|
|
114
123
|
if [ "$choice" = "2" ]; then
|
|
115
124
|
FRONTEND_INSTALL_PATH="./frontend"
|
|
@@ -129,11 +138,28 @@ echo -e "\n${GREEN}...config files & utilities${NC}"
|
|
|
129
138
|
safe_cat "${TEMPLATES_DIR}/_browserslistrc" .browserslistrc new
|
|
130
139
|
safe_cat "${TEMPLATES_DIR}/_editorconfig" .editorconfig new
|
|
131
140
|
safe_cat "${TEMPLATES_DIR}/_prettierrc" .prettierrc new
|
|
132
|
-
safe_cat "${TEMPLATES_DIR}/jsconfig.json" jsconfig.json new
|
|
133
|
-
safe_cat "${BASE_URL}/../../design-tokens/tokens-config-sample.mjs" tokens-config.mjs new
|
|
134
141
|
safe_cat "${TEMPLATES_DIR}/_root_htaccess" _root_htaccess
|
|
135
142
|
safe_cat "${TEMPLATES_DIR}/_root_robots.txt" _root_robots.txt
|
|
136
143
|
|
|
144
|
+
# jsconfig.json: sta SEMPRE nella root del progetto (è anche il file di
|
|
145
|
+
# riferimento di vscode). I suoi path sono quindi relativi alla root: il
|
|
146
|
+
# placeholder __FRONTEND__ viene risolto in base alla posizione scelta.
|
|
147
|
+
# NB: webpack.config.mjs lo cerca in root anche quando è in una sottodirectory
|
|
148
|
+
if [ "$FRONTEND_INSTALL_PATH" = "." ]; then
|
|
149
|
+
FRONTEND_REL="./"
|
|
150
|
+
else
|
|
151
|
+
FRONTEND_REL="./frontend/"
|
|
152
|
+
fi
|
|
153
|
+
JSCONFIG_TPL="${TEMPLATES_DIR}/jsconfig.json"
|
|
154
|
+
if [ ! -f "$JSCONFIG_TPL" ]; then
|
|
155
|
+
echo -e "${RED}Sorgente mancante: ${JSCONFIG_TPL}${NC}"
|
|
156
|
+
else
|
|
157
|
+
JSCONFIG_TMP="$(mktemp)"
|
|
158
|
+
sed "s|__FRONTEND__|${FRONTEND_REL}|g" "$JSCONFIG_TPL" >| "$JSCONFIG_TMP"
|
|
159
|
+
safe_cat "$JSCONFIG_TMP" jsconfig.json new
|
|
160
|
+
rm -f "$JSCONFIG_TMP"
|
|
161
|
+
fi
|
|
162
|
+
|
|
137
163
|
# code-workspace: se un file .code-workspace esiste già (qualunque sia il nome),
|
|
138
164
|
# le chiavi del template vengono aggiunte in fondo con prefisso '_'
|
|
139
165
|
WORKSPACE_TPL="${TEMPLATES_DIR}/__project__.code-workspace"
|
|
@@ -155,6 +181,9 @@ else
|
|
|
155
181
|
fi
|
|
156
182
|
|
|
157
183
|
|
|
184
|
+
echo -e "\n${GREEN}...minimo${NC}"
|
|
185
|
+
npm_i -S @massimo-cassandro/minimo
|
|
186
|
+
|
|
158
187
|
echo -e "\n${GREEN}...eslint${NC}"
|
|
159
188
|
npm_i -D @massimo-cassandro/eslint-config
|
|
160
189
|
safe_cat "${TEMPLATES_DIR}/eslint.config.mjs" eslint.config.mjs new
|
|
@@ -167,6 +196,7 @@ echo -e "\n${GREEN}...webpack${NC}"
|
|
|
167
196
|
npm_i -D webpack-cli webpack-dev-server webpack-manifest-plugin webpack
|
|
168
197
|
npm_i -D @babel/core @babel/preset-env babel-loader terser-webpack-plugin
|
|
169
198
|
npm_i -D webpack-remove-empty-scripts copy-webpack-plugin html-loader html-webpack-plugin
|
|
199
|
+
# npm_i -D @principalstudio/html-webpack-inject-preload file-loader # da installare solo se necessario
|
|
170
200
|
npm_i -D postcss autoprefixer postcss-custom-media @csstools/postcss-global-data postcss-loader postcss-preset-env
|
|
171
201
|
# NB: niente cssnano: la minificazione è di css-minimizer-webpack-plugin e cssnano
|
|
172
202
|
# nel loader postcss eliminerebbe i commenti `purgecss ignore` prima di PurgeCSS
|
|
@@ -180,7 +210,6 @@ npm_i -D purgecss-webpack-plugin glob
|
|
|
180
210
|
npm_i -D style-dictionary
|
|
181
211
|
|
|
182
212
|
safe_cat "${WEBPACK_SOURCE_DIR}/webpack.config.mjs" "${FRONTEND_INSTALL_PATH}/webpack.config.mjs"
|
|
183
|
-
safe_cat "${WEBPACK_SOURCE_DIR}/webpack-template.ejs" "${FRONTEND_INSTALL_PATH}/webpack-template.ejs"
|
|
184
213
|
|
|
185
214
|
# cartella webpack
|
|
186
215
|
WEBPACK_LOCAL_DIR="${FRONTEND_INSTALL_PATH}/webpack-modules"
|
|
@@ -202,28 +231,56 @@ for FILE in "${WEBPACK_MODULES_REMOTE_URL}"/*; do
|
|
|
202
231
|
safe_cat "$FILE" "${WEBPACK_LOCAL_DIR}/$(basename "$FILE")"
|
|
203
232
|
done
|
|
204
233
|
|
|
205
|
-
echo -e "\n${GREEN}Creating
|
|
234
|
+
echo -e "\n${GREEN}Creating your frontend application's folder structure${NC}"
|
|
235
|
+
|
|
236
|
+
# La struttura viene creata nella posizione scelta a inizio script, coerente con
|
|
237
|
+
# i percorsi attesi da webpack.config.mjs (`./src/...`, `./favicons/output`,
|
|
238
|
+
# `./error-pages/...`), da jsconfig.json (@css, @src, @icons, @imgs) e da
|
|
239
|
+
# postcss.config.mjs (`../src/css/custom-media.css`)
|
|
240
|
+
mkdir -p \
|
|
241
|
+
"${FRONTEND_INSTALL_PATH}/src/css" \
|
|
242
|
+
"${FRONTEND_INSTALL_PATH}/src/tpl" \
|
|
243
|
+
"${FRONTEND_INSTALL_PATH}/icons" \
|
|
244
|
+
"${FRONTEND_INSTALL_PATH}/imgs" \
|
|
245
|
+
"${FRONTEND_INSTALL_PATH}/favicons" \
|
|
246
|
+
"${FRONTEND_INSTALL_PATH}/error-pages"
|
|
247
|
+
|
|
248
|
+
# template html di webpack (HtmlWebpackPlugin: `./src/tpl/index.ejs`)
|
|
249
|
+
safe_cat "${WEBPACK_SOURCE_DIR}/webpack-template.ejs" "${FRONTEND_INSTALL_PATH}/src/tpl/index.ejs"
|
|
250
|
+
|
|
251
|
+
# Sorgenti di minimo da copiare nel progetto: si usa il pacchetto appena
|
|
252
|
+
# installato in node_modules (stessa versione che userà il progetto) e, in
|
|
253
|
+
# fallback, la dir da cui è lanciato questo script (repo o pacchetto estratto)
|
|
254
|
+
MINIMO_PKG_DIR=""
|
|
255
|
+
for CANDIDATE in "./node_modules/@massimo-cassandro/minimo" "${BASE_URL}/../.."; do
|
|
256
|
+
if [ -f "${CANDIDATE}/src/custom-properties.css" ]; then
|
|
257
|
+
MINIMO_PKG_DIR="$CANDIDATE"
|
|
258
|
+
break
|
|
259
|
+
fi
|
|
260
|
+
done
|
|
206
261
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
262
|
+
if [ -z "$MINIMO_PKG_DIR" ]; then
|
|
263
|
+
echo -e "${RED}Sorgenti di minimo non trovati (né in ./node_modules/@massimo-cassandro/minimo né in ${BASE_URL}/../..): css di base e tokens-config non copiati${NC}"
|
|
264
|
+
BLOCKED_FILES+=("css di base + tokens-config.mjs → sorgenti minimo non trovati")
|
|
265
|
+
else
|
|
266
|
+
echo "sorgenti minimo: ${MINIMO_PKG_DIR}"
|
|
212
267
|
|
|
213
|
-
#
|
|
214
|
-
#
|
|
215
|
-
|
|
216
|
-
for FILE in
|
|
217
|
-
|
|
218
|
-
done
|
|
268
|
+
# css di partenza del progetto: solo i file destinati a essere personalizzati.
|
|
269
|
+
# minimo.css NON viene copiato: i moduli css del framework vanno importati dal
|
|
270
|
+
# pacchetto (`@import '@minimo/css/...'`, vedi entry-tpl.css)
|
|
271
|
+
for FILE in custom-properties.css custom-media.css fonts.css; do
|
|
272
|
+
safe_cat "${MINIMO_PKG_DIR}/src/${FILE}" "${FRONTEND_INSTALL_PATH}/src/css/${FILE}"
|
|
273
|
+
done
|
|
219
274
|
|
|
220
|
-
#
|
|
221
|
-
|
|
275
|
+
# config di build-tokens: collocato accanto al css generato (custom-properties.css).
|
|
276
|
+
# NB: i percorsi relativi nel file vanno adattati alla sua posizione effettiva
|
|
277
|
+
safe_cat "${MINIMO_PKG_DIR}/design-tokens/tokens-config-sample.mjs" "${FRONTEND_INSTALL_PATH}/src/css/tokens-config.mjs"
|
|
278
|
+
fi
|
|
222
279
|
|
|
223
280
|
# template delle entry css (globale/di pagina e critical): ogni entry deve
|
|
224
281
|
# importare direttamente custom-properties.css (vedi commenti nei file stessi)
|
|
225
|
-
safe_cat "${TEMPLATES_DIR}/entry-tpl.css" "${
|
|
226
|
-
safe_cat "${TEMPLATES_DIR}/entry-tpl.critical.css" "${
|
|
282
|
+
safe_cat "${TEMPLATES_DIR}/entry-tpl.css" "${FRONTEND_INSTALL_PATH}/src/entry-tpl.css"
|
|
283
|
+
safe_cat "${TEMPLATES_DIR}/entry-tpl.critical.css" "${FRONTEND_INSTALL_PATH}/src/entry-tpl.critical.css"
|
|
227
284
|
|
|
228
285
|
set +C
|
|
229
286
|
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"settings": {
|
|
8
8
|
|
|
9
9
|
"cssvar.files": [
|
|
10
|
-
"frontend/css/custom-properties.css", // project props
|
|
10
|
+
"frontend/src/css/custom-properties.css", // project props (frontend in sottodirectory)
|
|
11
|
+
// "src/css/custom-properties.css", // project props (frontend nella root)
|
|
11
12
|
|
|
12
13
|
// OPEN PROPS
|
|
13
14
|
// "./node_modules/open-props/open-props.min.css", // all open-props
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"__help": "https://code.visualstudio.com/docs/languages/jsconfig",
|
|
3
|
+
"__note": "Tenere questo file ACCANTO a webpack.config.mjs: gli alias webpack sono ricavati da qui (get-jsConfig-aliases.mjs) e risolti a partire dalla posizione di questo file",
|
|
3
4
|
"compilerOptions": {
|
|
4
5
|
"ignoreDeprecations": "6.0",
|
|
5
6
|
"baseUrl": ".",
|
|
@@ -8,14 +9,14 @@
|
|
|
8
9
|
"target": "es2023",
|
|
9
10
|
"module": "ES6",
|
|
10
11
|
"paths": {
|
|
11
|
-
"@css/*": ["./
|
|
12
|
-
"@src/*": ["./
|
|
13
|
-
"@icons/*": ["./
|
|
14
|
-
"@imgs/*": ["./
|
|
15
|
-
"@frontend/*": ["
|
|
16
|
-
"@minimo/*": ["
|
|
17
|
-
"@minimoCharts/*": ["
|
|
12
|
+
"@css/*": ["./src/css/*"],
|
|
13
|
+
"@src/*": ["./src/*"],
|
|
14
|
+
"@icons/*": ["./icons/*"],
|
|
15
|
+
"@imgs/*": ["./imgs/*"],
|
|
16
|
+
"@frontend/*": ["./*"],
|
|
17
|
+
"@minimo/*": ["__NODE_MODULES__/@massimo-cassandro/minimo/src/*"],
|
|
18
|
+
"@minimoCharts/*": ["__NODE_MODULES__/@massimo-cassandro/minimo/charts/*"]
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
|
-
"exclude": ["
|
|
21
|
+
"exclude": ["__NODE_MODULES__", "dist", "docs", "build", "public"]
|
|
21
22
|
}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"webpack PROD": "npm run 'UPD-version' && NODE_ENV=production webpack --config ./webpack.config.mjs --stats minimal",
|
|
23
23
|
"eslint-check": "npx eslint app/ # or src/, frontend/src/ ...",
|
|
24
24
|
"create-favicons INIT": "npx create-favicons init",
|
|
25
|
-
"create-favicons": "npx create-favicons --dir=./
|
|
25
|
+
"create-favicons": "npx create-favicons --dir=./favicons # o ./frontend/favicons",
|
|
26
26
|
"UPD-version": "npx update-version # --log-file=./frontend/changelog.md --log-patch --pkg=alt/path/to/package.json",
|
|
27
27
|
"upd@m": "npx upd@m",
|
|
28
28
|
"launchChrome": "open -n -a 'Google Chrome' --args --profile-directory='Profile 3'",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"php server": "php -S localhost:8000 # -t root_dir/",
|
|
31
31
|
"symfony server": "symfony serve --port=8100 --listen-ip=0.0.0.0 # symfony server:stop # http://192.168.1.135:8100 # -d (deamon): rimane aperto anche dopo la chiusra del terminale",
|
|
32
32
|
"node server": "node serve # richiede ‘npm i serve’",
|
|
33
|
-
"build tokens": "npx buildTokens --config ./
|
|
34
|
-
"check unresolved props": "npx checkUnresolvedProps --config ./
|
|
33
|
+
"build tokens": "npx buildTokens --config ./src/css/tokens-config.mjs # o ./frontend/src/css/tokens-config.mjs",
|
|
34
|
+
"check unresolved props": "npx checkUnresolvedProps --config ./src/css/tokens-config.mjs # o ./frontend/src/css/tokens-config.mjs",
|
|
35
35
|
"npm-outdated": "npm outdated",
|
|
36
36
|
"npm-upd": "npm update --save"
|
|
37
37
|
},
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
+
<!-- template html di webpack: installato in <frontend>/src/tpl/index.ejs
|
|
3
|
+
(vedi HtmlWebpackPlugin in webpack.config.mjs).
|
|
4
|
+
I require sono relativi a QUESTO file. -->
|
|
2
5
|
<html lang="it">
|
|
3
6
|
<head>
|
|
4
7
|
<meta charset="utf-8">
|
|
5
8
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
6
9
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
7
10
|
|
|
8
|
-
<!-- favicons -->
|
|
9
|
-
<%= require('
|
|
10
|
-
<!-- <%= require('./app/favicons/output/favicons.incl.ejs')({}) %> -->
|
|
11
|
-
<!-- <%= require('./frontend/favicons/output/favicons.incl.ejs')({}) %> -->
|
|
11
|
+
<!-- favicons (generate da `npx create-favicons`, vedi package.json) -->
|
|
12
|
+
<%= require('../../favicons/output/favicons.incl.ejs')({}) %>
|
|
12
13
|
|
|
13
14
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
14
15
|
<!-- <base href="<%= htmlWebpackPlugin.options.base %>"> -->
|
|
@@ -24,21 +24,41 @@ import { getJsConfigAliases } from './webpack-modules/get-jsConfig-aliases.mjs';
|
|
|
24
24
|
import { svgRules } from './webpack-modules/svg-rules.mjs';
|
|
25
25
|
|
|
26
26
|
// --- config ---
|
|
27
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
28
|
+
,__dirname = path.dirname(__filename);
|
|
29
|
+
|
|
30
|
+
// Risolve un percorso a partire dalla root del progetto, che coincide con la dir
|
|
31
|
+
// di questo file solo se il frontend NON è in una sottodirectory (es. ./frontend):
|
|
32
|
+
// vengono provate entrambe le posizioni, in fallback la prima
|
|
33
|
+
const fromProjectRoot = (relPath) => {
|
|
34
|
+
const candidates = ['./', '../'].map(p => path.resolve(__dirname, p, relPath));
|
|
35
|
+
return candidates.find(p => fs.existsSync(p)) ?? candidates[0];
|
|
36
|
+
};
|
|
37
|
+
|
|
27
38
|
const isDevelopment = process.env.NODE_ENV === 'development'
|
|
28
|
-
,__filename = fileURLToPath(import.meta.url)
|
|
29
|
-
,__dirname = path.dirname(__filename)
|
|
30
39
|
,useSass = false
|
|
31
40
|
,inlineCssInDevMode = true
|
|
32
41
|
,useSvgo = true
|
|
33
42
|
,useSvgr = false // svg per react
|
|
34
43
|
,svgoConfig = useSvgo? (await import('./webpack-modules/svgo.config.mjs')).default : null
|
|
35
44
|
,postcssConfig_path = path.resolve(__dirname, './webpack-modules/postcss.config.mjs')
|
|
45
|
+
// dir di output: relativa a QUESTO file ('../build' se il frontend è in una
|
|
46
|
+
// sottodirectory, './build' se webpack.config.mjs è nella root del progetto)
|
|
36
47
|
,output_dir = path.resolve(__dirname, '../build')
|
|
37
48
|
// ,output_dir = isDevelopment? '_dev' : 'build' // symfony
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
// dir delle favicons generate da `npx create-favicons` (vedi package.json):
|
|
50
|
+
// il path assoluto serve a CopyWebpackPlugin/HtmlWebpackPlugin (i path
|
|
51
|
+
// relativi sarebbero risolti dal cwd, non da questo file), mentre la regexp
|
|
52
|
+
// resta relativa perché viene confrontata con i path dei moduli
|
|
53
|
+
,favicons_path = path.resolve(__dirname, './favicons/output')
|
|
54
|
+
,favicons_path_regexp = /favicons\/output/ // source pattern per le favicons (regexp o null)
|
|
55
|
+
// NB: jsconfig.json va tenuto in questa stessa dir (gli alias sono risolti
|
|
56
|
+
// a partire dalla sua posizione)
|
|
40
57
|
,jsConfigAliases = getJsConfigAliases(path.resolve(__dirname, './jsconfig.json'))
|
|
41
|
-
,packageJson = JSON.parse(fs.readFileSync(
|
|
58
|
+
,packageJson = JSON.parse(fs.readFileSync(fromProjectRoot('package.json'), 'utf-8'))
|
|
59
|
+
// path del pacchetto minimo (il suo js genera markup con classi proprie e il
|
|
60
|
+
// suo css dichiara custom properties: entrambi vanno visti da PurgeCSS)
|
|
61
|
+
,minimo_path = fromProjectRoot('node_modules/@massimo-cassandro/minimo')
|
|
42
62
|
,usePurgeCss = true // false per disattivare PurgeCSS (debug rapido di problemi legati al purge)
|
|
43
63
|
,purgeCSSOptions = {
|
|
44
64
|
variables: false, // rimuove le custom properties non usate (sostituisce jit-props)
|
|
@@ -91,7 +111,7 @@ const shared_chunk_paths = (module) => {
|
|
|
91
111
|
// https://github.com/webpack/copy-webpack-plugin/tree/main?tab=readme-ov-file#copy-webpack-plugin
|
|
92
112
|
const CopyWebpackPluginPatterns = [
|
|
93
113
|
{
|
|
94
|
-
from:
|
|
114
|
+
from: `${favicons_path}/icon-*.png`,
|
|
95
115
|
to: '[name][ext]'
|
|
96
116
|
},
|
|
97
117
|
// {
|
|
@@ -115,110 +135,9 @@ const CopyWebpackPluginPatterns = [
|
|
|
115
135
|
// }
|
|
116
136
|
];
|
|
117
137
|
|
|
118
|
-
// =>> PurgeCSS
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
// così i problemi di purge emergono subito durante lo sviluppo:
|
|
122
|
-
// - `purgeCSSPluginCritical`: solo le entry `*.critical` (purge stretto, gli asset
|
|
123
|
-
// devono essere autosufficienti e minimi perché inlinati nei template html)
|
|
124
|
-
// - `purgeCSSPlugin`: tutti gli asset (il doppio passaggio sui critical è idempotente)
|
|
125
|
-
//
|
|
126
|
-
// NB (watch mode): i template twig NON sono osservati da webpack: dopo aver
|
|
127
|
-
// aggiunto una classe solo in un twig occorre rilanciare la build (o toccare
|
|
128
|
-
// un file js/css) perché il purge venga ricalcolato.
|
|
129
|
-
// NB (dev): il plugin agisce solo sugli asset css emessi; con
|
|
130
|
-
// `inlineCssInDevMode: true` i css non-critical in dev sono iniettati da
|
|
131
|
-
// style-loader e non vengono purgati (i critical passano comunque da
|
|
132
|
-
// MiniCssExtract e sono sempre purgati)
|
|
133
|
-
|
|
134
|
-
// `paths`: SOLO file che generano markup o classi (html/ejs, twig, php, js);
|
|
135
|
-
// NIENTE file css tra i paths: verrebbero letti come "contenuto" e ogni selettore
|
|
136
|
-
// risulterebbe usato, vanificando il purge
|
|
137
|
-
const purgeCSSCommonOptions = {
|
|
138
|
-
paths: () => globSync(
|
|
139
|
-
[
|
|
140
|
-
path.resolve(__dirname, './src/**/*.{js,mjs,jsx}'),
|
|
141
|
-
path.resolve(__dirname, './*.ejs'), // template html di webpack
|
|
142
|
-
path.resolve(__dirname, './src/**/*.ejs'),
|
|
143
|
-
// progetti symfony: template twig e classi generate lato php
|
|
144
|
-
// path.resolve(__dirname, '../templates/**/*.twig'),
|
|
145
|
-
// path.resolve(__dirname, '../src/**/*.php'),
|
|
146
|
-
// il js di minimo genera markup con classi proprie (snackbar, unsplash-page, ecc.)
|
|
147
|
-
// NB: adattare il percorso di node_modules se questo config è in una
|
|
148
|
-
// sottodirectory del progetto (es. frontend/ → '../node_modules/...')
|
|
149
|
-
path.resolve(__dirname, './node_modules/@massimo-cassandro/minimo/src/**/*.{js,mjs}'),
|
|
150
|
-
],
|
|
151
|
-
{ nodir: true }
|
|
152
|
-
),
|
|
153
|
-
|
|
154
|
-
// extractor di default (/[A-Za-z0-9_-]+/g): adeguato a classi/tag/id,
|
|
155
|
-
// NON definire extractors custom (il vecchio /[A-z0-9-:/]+/ era buggato:
|
|
156
|
-
// il range [A-z] include caratteri non voluti come `[`, `\`, `^`, ...)
|
|
157
|
-
|
|
158
|
-
variables: true, // rimuove le custom properties non usate (sostituisce postcss-jit-props)
|
|
159
|
-
keyframes: true, // rimuove i @keyframes non referenziati
|
|
160
|
-
// fontFace resta false (default): i font sono referenziati solo tramite
|
|
161
|
-
// var(--font-family) e purgecss non risolve le custom properties nei valori,
|
|
162
|
-
// quindi con `true` i @font-face verrebbero rimossi anche se usati
|
|
163
|
-
|
|
164
|
-
rejected: purgeCSSDebug // popola purgedStats per il log di debug
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// safelist base minima, comune alle due istanze
|
|
168
|
-
const purgeCSSSafelistBase = {
|
|
169
|
-
standard: [
|
|
170
|
-
// classi costruite dinamicamente nei template o lato server, invisibili
|
|
171
|
-
// all'analisi statica dei paths. Esempio (da adattare al progetto):
|
|
172
|
-
// flash messages twig con class="alert alert-{{ label }}"
|
|
173
|
-
/^alert-(success|notice|error|warning)$/
|
|
174
|
-
],
|
|
175
|
-
deep: [
|
|
176
|
-
// css modules: prefisso `m_` presente in dev e prod (vedi css-rules.mjs),
|
|
177
|
-
// le classi hashate non possono comparire nei file scansionati
|
|
178
|
-
/^m_/
|
|
179
|
-
],
|
|
180
|
-
greedy: [
|
|
181
|
-
// INDISPENSABILE: purgecss non riconosce il nesting selector nativo e senza
|
|
182
|
-
// questo pattern i selettori annidati composti solo da `&` + pseudo classi
|
|
183
|
-
// (&:hover, &:focus-visible, `&` semplice, ecc.) verrebbero SEMPRE rimossi
|
|
184
|
-
/^&$/
|
|
185
|
-
]
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// css della pagina critici (inlinati nei template): purge stretto,
|
|
189
|
-
// devono essere autosufficienti e minimi
|
|
190
|
-
const purgeCSSPluginCritical = new PurgeCSSPlugin({
|
|
191
|
-
...purgeCSSCommonOptions,
|
|
192
|
-
only: ['.critical'],
|
|
193
|
-
safelist: purgeCSSSafelistBase
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// tutti gli altri asset (il purge è idempotente: il secondo passaggio
|
|
197
|
-
// sui critical non rimuove altro)
|
|
198
|
-
const purgeCSSPlugin = new PurgeCSSPlugin({
|
|
199
|
-
...purgeCSSCommonOptions,
|
|
200
|
-
safelist: {
|
|
201
|
-
...purgeCSSSafelistBase,
|
|
202
|
-
// elenco generato: usi di var() nei blocchi `purgecss ignore` e nei css
|
|
203
|
-
// shadow-DOM/`?raw`, override cross-asset (seeds), con chiusura transitiva
|
|
204
|
-
// delle dipendenze (vedi webpack-modules/purgecss-variables-safelist.mjs)
|
|
205
|
-
variables: purgecssVariablesSafelist({
|
|
206
|
-
declarationGlobs: [
|
|
207
|
-
path.resolve(__dirname, './src/**/*.css'),
|
|
208
|
-
path.resolve(__dirname, './node_modules/@massimo-cassandro/minimo/src/**/*.css'),
|
|
209
|
-
],
|
|
210
|
-
shadowGlobs: [
|
|
211
|
-
path.resolve(__dirname, './src/web-components/**/*.css'),
|
|
212
|
-
path.resolve(__dirname, './node_modules/@massimo-cassandro/minimo/src/web-components/**/*.css'),
|
|
213
|
-
],
|
|
214
|
-
seeds: [
|
|
215
|
-
// props dichiarate in un asset ma consumate in un altro (es. override
|
|
216
|
-
// di tema definiti nel css di una pagina e consumati dal css globale):
|
|
217
|
-
// indicarle qui per nome ('--btn-primary-bg') o pattern (/^--btn-/)
|
|
218
|
-
]
|
|
219
|
-
})
|
|
220
|
-
}
|
|
221
|
-
});
|
|
138
|
+
// =>> PurgeCSS
|
|
139
|
+
// Istanze e opzioni sono in webpack-modules/purgecss-setup.mjs: qui restano
|
|
140
|
+
// solo i flag e i dati di progetto (vedi createPurgeCSSPlugins nei `plugins`).
|
|
222
141
|
|
|
223
142
|
// recupero metadata immagini
|
|
224
143
|
// const require = createRequire(import.meta.url);
|
|
@@ -235,7 +154,7 @@ const entries = {
|
|
|
235
154
|
|
|
236
155
|
// css critici inlinati nei template html: il suffisso `.critical` nel nome
|
|
237
156
|
// della entry attiva l'istanza PurgeCSS dedicata con purge stretto
|
|
238
|
-
// (vedi
|
|
157
|
+
// (vedi purgecss-setup.mjs) e la regola dedicata in css-rules.mjs
|
|
239
158
|
// ,'xxxxxx.critical': './src/xxxxxx.critical.css'
|
|
240
159
|
};
|
|
241
160
|
|
|
@@ -393,7 +312,7 @@ const config = {
|
|
|
393
312
|
// =>> plugins: HtmlWebpackPlugin (manifest)
|
|
394
313
|
new HtmlWebpackPlugin({
|
|
395
314
|
filename: 'manifest.webmanifest',
|
|
396
|
-
template: path.resolve(
|
|
315
|
+
template: path.resolve(favicons_path, './manifest.webmanifest.ejs'),
|
|
397
316
|
inject: false,
|
|
398
317
|
minify: false //!isDevelopment
|
|
399
318
|
}),
|
|
@@ -487,12 +406,16 @@ const config = {
|
|
|
487
406
|
// SOLO file che generano markup o classi (twig, php, js);
|
|
488
407
|
// i file di stile vengono comunque scartati dal plugin
|
|
489
408
|
contentGlobs: [
|
|
490
|
-
|
|
491
|
-
|
|
409
|
+
// progetti symfony: template twig e classi generate lato php
|
|
410
|
+
// (percorsi relativi alla root del progetto: adattare il `../` se
|
|
411
|
+
// webpack.config.mjs NON è in una sottodirectory)
|
|
412
|
+
// path.resolve(__dirname, '../templates/**/*.twig'),
|
|
413
|
+
// path.resolve(__dirname, '../src/**/*.php'),
|
|
492
414
|
path.resolve(__dirname, './src/**/*.{js,mjs,jsx}'),
|
|
415
|
+
path.resolve(__dirname, './src/**/*.ejs'), // template html di webpack
|
|
493
416
|
path.resolve(__dirname, './error-pages/**/*.js'),
|
|
494
417
|
// il js di minimo genera markup con classi proprie (snackbar, unsplash-page, ecc.)
|
|
495
|
-
|
|
418
|
+
`${minimo_path}/src/**/*.{js,mjs}`,
|
|
496
419
|
],
|
|
497
420
|
|
|
498
421
|
safelist: {
|
|
@@ -529,11 +452,11 @@ const config = {
|
|
|
529
452
|
declarationGlobs: [
|
|
530
453
|
path.resolve(__dirname, './src/**/*.css'),
|
|
531
454
|
path.resolve(__dirname, './error-pages/**/*.css'),
|
|
532
|
-
|
|
455
|
+
`${minimo_path}/src/**/*.css`,
|
|
533
456
|
],
|
|
534
457
|
shadowGlobs: [
|
|
535
458
|
path.resolve(__dirname, './src/web-components/**/*.css'),
|
|
536
|
-
|
|
459
|
+
`${minimo_path}/src/web-components/**/*.css`,
|
|
537
460
|
],
|
|
538
461
|
seeds: [
|
|
539
462
|
// override di .login-group (login.css) consumati dai buttons minimo (css globale)
|