@mpxjs/webpack-plugin 2.7.57 → 2.7.58

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/index.js CHANGED
@@ -58,6 +58,7 @@ const stringifyLoadersAndResource = require('./utils/stringify-loaders-resource'
58
58
  const emitFile = require('./utils/emit-file')
59
59
  const { MPX_PROCESSED_FLAG, MPX_DISABLE_EXTRACTOR_CACHE } = require('./utils/const')
60
60
  const isEmptyObject = require('./utils/is-empty-object')
61
+ require('./utils/check-core-version-match')
61
62
 
62
63
  const isProductionLikeMode = options => {
63
64
  return options.mode === 'production' || !options.mode
@@ -119,7 +119,8 @@ module.exports = function (content) {
119
119
  if (err) return nativeCallback(err)
120
120
  let output = `var json = ${JSON.stringify(json, null, 2)};\n`
121
121
  if (processOutput) output = processOutput(output)
122
- output += `module.exports = JSON.stringify(json, null, 2);\n`
122
+ const jsonSpace = this.minimize ? 0 : 2
123
+ output += `module.exports = JSON.stringify(json, null, ${jsonSpace});\n`
123
124
  nativeCallback(null, output)
124
125
  }
125
126
 
@@ -0,0 +1,18 @@
1
+ // @mpxjs/webpack-plugin 2.7.x -> @mpxjs/core 2.7.x
2
+ // @mpxjs/webpack-plugin 2.8.x -> @mpxjs/core 2.8.x
3
+ const coreVersion = require('@mpxjs/core/package.json').version
4
+ const packageName = require('../../package.json').name
5
+ const packageVersion = require('../../package.json').version
6
+
7
+ if (packageVersion.slice(0, 3) !== coreVersion.slice(0, 3)) {
8
+ const corePath = require.resolve('@mpxjs/core')
9
+ const packagePath = require.resolve('../../package.json')
10
+ throw new Error(
11
+ `@mpxjs/core packages version mismatch:
12
+ -@mpxjs/core@${coreVersion}(${corePath})
13
+ -${packageName}@${packageVersion}(${packagePath})
14
+ This may cause things to work incorrectly, Make sure to use the same minor version for both.
15
+ For example: @mpxjs/core@2.7.x with @mpxjs/webpack-plugin@2.7.x
16
+ `
17
+ )
18
+ }
@@ -144,6 +144,20 @@ module.exports = async function loader (content, map, meta) {
144
144
  )
145
145
  }
146
146
 
147
+ if (this.minimize) {
148
+ const cssnano = require('cssnano')
149
+ const minimizeOptions = rawOptions.minimize || {}
150
+ let cssnanoConfig = {
151
+ preset: ['cssnano-preset-default', minimizeOptions.optimisation || {}]
152
+ }
153
+ if (minimizeOptions.advanced) {
154
+ cssnanoConfig = {
155
+ preset: ['cssnano-preset-advanced', minimizeOptions.optimisation || {}]
156
+ }
157
+ }
158
+ plugins.push(cssnano(cssnanoConfig))
159
+ }
160
+
147
161
  // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
148
162
  if (meta) {
149
163
  const { ast } = meta
@@ -203,6 +203,11 @@
203
203
  "description": "Allows exporting styles as array with modules, string or constructable stylesheet (i.e. `CSSStyleSheet`).",
204
204
  "link": "https://github.com/webpack-contrib/css-loader#exporttype",
205
205
  "enum": ["array", "string", "css-style-sheet"]
206
+ },
207
+ "minimize": {
208
+ "description": "css minimization config.",
209
+ "link": "https://www.cssnano.cn/docs/what-are-optimisations/",
210
+ "type": "object"
206
211
  }
207
212
  },
208
213
  "type": "object"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.57",
3
+ "version": "2.7.58",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=14.14.0"
82
82
  },
83
- "gitHead": "d880e6a7cbce97d3b8cce3468619683d7c062837"
83
+ "gitHead": "bb48b5989cd2c89ba464ac1ee53529431d56fb33"
84
84
  }