@nitro/webpack 11.0.5 → 11.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitro/webpack",
3
- "version": "11.0.5",
3
+ "version": "11.0.7",
4
4
  "description": "nitro webpack",
5
5
  "license": "MIT",
6
6
  "author": "The Nitro Team",
@@ -22,7 +22,7 @@
22
22
  "nitro"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@nitro/app": ">=11.0.5",
25
+ "@nitro/app": ">=11.0.7",
26
26
  "webpack": "^5"
27
27
  },
28
28
  "dependencies": {
@@ -32,21 +32,23 @@
32
32
  "@babel/plugin-proposal-decorators": "7.29.0",
33
33
  "@babel/plugin-transform-class-properties": "7.28.6",
34
34
  "autoprefixer": "10.4.27",
35
- "babel-loader": "10.0.0",
35
+ "babel-loader": "10.1.1",
36
36
  "case-sensitive-paths-webpack-plugin": "2.4.0",
37
37
  "css-loader": "7.1.4",
38
- "cssnano": "7.1.2",
38
+ "css-minimizer-webpack-plugin": "8.0.0",
39
+ "cssnano": "7.1.3",
39
40
  "config": "4.4.1",
40
41
  "image-minimizer-webpack-plugin": "5.0.0",
41
42
  "fork-ts-checker-webpack-plugin": "9.1.0",
42
43
  "handlebars-loader": "1.7.3",
43
44
  "imagemin": "9.0.1",
44
- "mini-css-extract-plugin": "2.10.0",
45
+ "mini-css-extract-plugin": "2.10.1",
45
46
  "postcss": "8.5.8",
46
47
  "postcss-loader": "8.2.1",
47
48
  "resolve-url-loader": "5.0.0",
48
- "sass": "1.97.3",
49
+ "sass": "1.98.0",
49
50
  "sass-loader": "16.0.7",
51
+ "terser-webpack-plugin": "5.4.0",
50
52
  "thread-loader": "4.0.4",
51
53
  "ts-loader": "9.5.4",
52
54
  "typescript": "5.9.3",
package/readme.md CHANGED
@@ -8,7 +8,7 @@ Configurable and easy to use webpack 5 config for nitro projects.
8
8
 
9
9
  ## Usage
10
10
 
11
- ```
11
+ ```js
12
12
  const options = {
13
13
  rules: {
14
14
  script: true,
@@ -212,7 +212,7 @@ module.exports = (options = { rules: {}, features: {} }) => {
212
212
  // images
213
213
  if (options.rules.image) {
214
214
  const imageRule = {
215
- test: /\.(png|jpg|gif|svg)$/,
215
+ test: /\.(png|jpe?g|gif|svg|webp)$/i,
216
216
  type: 'asset',
217
217
  parser: {
218
218
  dataUrlCondition: {
@@ -220,7 +220,11 @@ module.exports = (options = { rules: {}, features: {} }) => {
220
220
  },
221
221
  },
222
222
  generator: {
223
- filename: 'media/[ext]/[name]-[contenthash:7][ext]',
223
+ filename: (pathData) => {
224
+ const match = pathData.filename.match(/\.([^.?#]+)(?:[?#].*)?$/);
225
+ const extNoDot = match ? match[1] : 'asset';
226
+ return `media/${extNoDot}/[name]-[contenthash:7][ext]`;
227
+ },
224
228
  },
225
229
  };
226
230
  webpackConfig.module.rules.push(utils.getEnrichedConfig(imageRule, options.rules.image));
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const webpack = require('webpack');
4
4
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5
5
  const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
6
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
6
7
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
8
  const TerserPlugin = require('terser-webpack-plugin');
8
9
  const WebpackBar = require('webpackbar');
@@ -17,9 +18,11 @@ const bannerData = {
17
18
  pkg: require(`${appDirectory}/package.json`),
18
19
  };
19
20
 
20
- const banner = `${bannerData.pkg.name}
21
- @version v${bannerData.pkg.version}
22
- @date ${bannerData.date}`;
21
+ const bannerContent = `/**
22
+ * ${bannerData.pkg.name}
23
+ * @version v${bannerData.pkg.version}
24
+ * @date ${bannerData.date}
25
+ */`;
23
26
 
24
27
  module.exports = (options = { rules: {}, features: {} }) => {
25
28
  const imageMinimizerPlugins = [];
@@ -68,7 +71,48 @@ module.exports = (options = { rules: {}, features: {} }) => {
68
71
  );
69
72
  }
70
73
 
71
- const minimizerPlugins = [new TerserPlugin({ extractComments: false })];
74
+ const escapedPackageName = bannerData.pkg.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
75
+ const packageNameRegExp = new RegExp(escapedPackageName);
76
+
77
+ const minimizerPlugins = [
78
+ new TerserPlugin({
79
+ extractComments: {
80
+ condition: /@license|@preserve|^!/i,
81
+ filename: (file) => {
82
+ const entryName = file.basename
83
+ .replace(/\.min/, '')
84
+ .replace(/\.js$/, '');
85
+
86
+ return `${entryName}.license.txt`;
87
+ },
88
+ banner: (licenseFile) => `See ../${licenseFile} for license information`,
89
+ },
90
+ terserOptions: {
91
+ format: {
92
+ comments: packageNameRegExp,
93
+ },
94
+ // compress: true,
95
+ // mangle: true,
96
+ },
97
+ parallel: true,
98
+ }),
99
+ new CssMinimizerPlugin({
100
+ parallel: false,
101
+ minimizerOptions: {
102
+ preset: [
103
+ 'default',
104
+ {
105
+ discardComments: {
106
+ remove: (comment) => {
107
+ return !packageNameRegExp.test(comment);
108
+ },
109
+ },
110
+ },
111
+ ],
112
+ },
113
+ }),
114
+ ];
115
+
72
116
  if (!(options.features.imageMinimizer === false || imageMinimizerPlugins.length === 0)) {
73
117
  minimizerPlugins.push(
74
118
  new ImageMinimizerPlugin({
@@ -277,7 +321,7 @@ module.exports = (options = { rules: {}, features: {} }) => {
277
321
  // images
278
322
  if (options.rules.image) {
279
323
  const imageRule = {
280
- test: /\.(png|jpg|gif|svg)$/,
324
+ test: /\.(png|jpe?g|gif|svg|webp)$/i,
281
325
  type: 'asset',
282
326
  parser: {
283
327
  dataUrlCondition: {
@@ -285,7 +329,11 @@ module.exports = (options = { rules: {}, features: {} }) => {
285
329
  },
286
330
  },
287
331
  generator: {
288
- filename: 'media/[ext]/[name]-[contenthash:7][ext]',
332
+ filename: (pathData) => {
333
+ const match = pathData.filename.match(/\.([^.?#]+)(?:[?#].*)?$/);
334
+ const extNoDot = match ? match[1] : 'asset';
335
+ return `media/${extNoDot}/[name]-[contenthash:7][ext]`;
336
+ },
289
337
  },
290
338
  };
291
339
 
@@ -294,7 +342,11 @@ module.exports = (options = { rules: {}, features: {} }) => {
294
342
 
295
343
  // feature banner (enabled by default)
296
344
  if (!options.features.banner === false) {
297
- webpackConfig.plugins.push(new webpack.BannerPlugin({ banner, entryOnly: true }));
345
+ webpackConfig.plugins.push(new webpack.BannerPlugin({
346
+ banner: bannerContent.trim(),
347
+ raw: true,
348
+ entryOnly: true,
349
+ }));
298
350
  }
299
351
 
300
352
  // feature bundle analyzer