@nitro/webpack 6.0.9 → 6.1.0

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/lib/utils.js CHANGED
@@ -15,6 +15,18 @@ function getEnrichedConfig(rule, config) {
15
15
  return rule;
16
16
  }
17
17
 
18
+ // load optional package
19
+ function getOptionalPackage(x) {
20
+ let mod;
21
+ try {
22
+ mod = require(x);
23
+ } catch (error) {
24
+ mod = null;
25
+ }
26
+ return mod;
27
+ }
28
+
18
29
  module.exports = {
19
30
  getEnrichedConfig,
31
+ getOptionalPackage,
20
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitro/webpack",
3
- "version": "6.0.9",
3
+ "version": "6.1.0",
4
4
  "description": "nitro webpack",
5
5
  "license": "MIT",
6
6
  "author": "The Nitro Team",
@@ -23,18 +23,18 @@
23
23
  "nitro"
24
24
  ],
25
25
  "dependencies": {
26
- "@babel/core": "7.17.5",
26
+ "@babel/core": "7.17.9",
27
27
  "@babel/preset-env": "7.16.11",
28
28
  "@babel/preset-react": "7.16.7",
29
- "@babel/plugin-proposal-decorators": "7.17.2",
29
+ "@babel/plugin-proposal-decorators": "7.17.9",
30
30
  "@babel/plugin-proposal-class-properties": "7.16.7",
31
31
  "@babel/plugin-syntax-dynamic-import": "7.8.3",
32
- "autoprefixer": "10.4.2",
32
+ "autoprefixer": "10.4.4",
33
33
  "case-sensitive-paths-webpack-plugin": "2.4.0",
34
34
  "css-loader": "5.2.7",
35
35
  "eslint": "7.32.0",
36
36
  "eslint-webpack-plugin": "2.5.4",
37
- "eslint-plugin-import": "2.25.4",
37
+ "eslint-plugin-import": "2.26.0",
38
38
  "file-loader": "6.2.0",
39
39
  "handlebars-loader": "1.7.1",
40
40
  "iconfont-webpack-plugin": "5.0.1",
@@ -43,16 +43,16 @@
43
43
  "js-config-webpack-plugin": "2.0.3",
44
44
  "mini-css-extract-plugin": "1.6.2",
45
45
  "optimize-css-assets-webpack-plugin": "6.0.1",
46
- "postcss": "8.4.7",
46
+ "postcss": "8.4.12",
47
47
  "postcss-loader": "4.3.0",
48
48
  "resolve-url-loader": "5.0.0",
49
- "sass": "1.49.9",
49
+ "sass": "1.50.1",
50
50
  "sass-loader": "10.2.1",
51
51
  "stylelint": "13.13.1",
52
52
  "stylelint-webpack-plugin": "2.2.2",
53
53
  "svgo": "2.8.0",
54
54
  "ts-config-webpack-plugin": "2.0.3",
55
- "typescript": "4.5.5",
55
+ "typescript": "4.6.3",
56
56
  "url-loader": "4.1.1",
57
57
  "webpack": "4.46.0",
58
58
  "webpackbar": "5.0.2",
@@ -218,6 +218,17 @@ module.exports = (options = { rules: {}, features: {} }) => {
218
218
 
219
219
  // images
220
220
  if (options.rules.image) {
221
+
222
+ const imageminMozjpeg = utils.getOptionalPackage('imagemin-mozjpeg');
223
+ const imageminOptipng = utils.getOptionalPackage('imagemin-optipng');
224
+ const imageminPngquant = utils.getOptionalPackage('imagemin-pngquant');
225
+ const imageminSvgo = utils.getOptionalPackage('imagemin-svgo');
226
+
227
+ // console.log('imagemin-mozjpeg: ', imageminMozjpeg ? 'installed' : 'NOT');
228
+ // console.log('imagemin-optipng: ', imageminOptipng ? 'installed' : 'NOT');
229
+ // console.log('imagemin-pngquant: ', imageminPngquant ? 'installed' : 'NOT');
230
+ // console.log('imagemin-svgo: ', imageminSvgo ? 'installed' : 'NOT');
231
+
221
232
  // image loader & minification
222
233
  const imageMinificationRule = {
223
234
  test: /\.(png|jpg|svg)$/,
@@ -226,35 +237,51 @@ module.exports = (options = { rules: {}, features: {} }) => {
226
237
  use: {
227
238
  loader: require.resolve('img-loader'),
228
239
  options: {
229
- plugins: [
230
- require('imagemin-mozjpeg')({
231
- quality: 75,
232
- progressive: true,
233
- }),
234
- require('imagemin-optipng')({
235
- optimizationLevel: 7,
236
- }),
237
- require('imagemin-pngquant')({
238
- // floyd: 0.5,
239
- // speed: 2
240
- }),
241
- require('imagemin-svgo')({
242
- plugins: [
243
- {
244
- name: 'preset-default',
245
- params: {
246
- overrides: {
247
- removeViewBox: false,
248
- },
249
- },
250
- },
251
- ],
252
- }),
253
- ],
240
+ plugins: [],
254
241
  },
255
242
  },
256
243
  };
257
244
 
245
+ if (imageminMozjpeg) {
246
+ imageMinificationRule.use.options.plugins.push(
247
+ imageminMozjpeg({
248
+ quality: 75,
249
+ progressive: true,
250
+ })
251
+ );
252
+ }
253
+ if (imageminOptipng) {
254
+ imageMinificationRule.use.options.plugins.push(
255
+ imageminOptipng({
256
+ optimizationLevel: 7,
257
+ })
258
+ );
259
+ }
260
+ if (imageminPngquant) {
261
+ imageMinificationRule.use.options.plugins.push(
262
+ imageminPngquant({
263
+ // floyd: 0.5,
264
+ // speed: 2
265
+ })
266
+ );
267
+ }
268
+ if (imageminSvgo) {
269
+ imageMinificationRule.use.options.plugins.push(
270
+ imageminSvgo({
271
+ plugins: [
272
+ {
273
+ name: 'preset-default',
274
+ params: {
275
+ overrides: {
276
+ removeViewBox: false,
277
+ },
278
+ },
279
+ },
280
+ ],
281
+ })
282
+ );
283
+ }
284
+
258
285
  // url loader for images (for example, in CSS files)
259
286
  // inlines assets below a limit
260
287
  const imageRule = {