@mpxjs/webpack-plugin 2.7.10 → 2.7.13
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 +16 -6
- package/lib/loader.js +1 -1
- package/lib/native-loader.js +1 -1
- package/lib/resolver/AddEnvPlugin.js +1 -1
- package/lib/resolver/AddModePlugin.js +1 -1
- package/lib/runtime/components/web/mpx-image.vue +8 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/template-compiler/compiler.js +75 -44
- package/lib/template-compiler/index.js +1 -1
- package/lib/utils/match-condition.js +4 -1
- package/lib/web/processTemplate.js +1 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const CommonJsAsyncDependency = require('./dependencies/CommonJsAsyncDependency'
|
|
|
11
11
|
const NormalModule = require('webpack/lib/NormalModule')
|
|
12
12
|
const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
13
13
|
const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
|
|
14
|
+
const FileSystemInfo = require('webpack/lib/FileSystemInfo')
|
|
14
15
|
const normalize = require('./utils/normalize')
|
|
15
16
|
const toPosix = require('./utils/to-posix')
|
|
16
17
|
const addQuery = require('./utils/add-query')
|
|
@@ -34,7 +35,7 @@ const RemoveEntryDependency = require('./dependencies/RemoveEntryDependency')
|
|
|
34
35
|
const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin')
|
|
35
36
|
const fixRelative = require('./utils/fix-relative')
|
|
36
37
|
const parseRequest = require('./utils/parse-request')
|
|
37
|
-
const matchCondition = require('./utils/match-condition')
|
|
38
|
+
const { matchCondition } = require('./utils/match-condition')
|
|
38
39
|
const { preProcessDefs } = require('./utils/index')
|
|
39
40
|
const config = require('./config')
|
|
40
41
|
const hash = require('hash-sum')
|
|
@@ -159,6 +160,14 @@ class MpxWebpackPlugin {
|
|
|
159
160
|
}, options.nativeConfig)
|
|
160
161
|
options.webConfig = options.webConfig || {}
|
|
161
162
|
this.options = options
|
|
163
|
+
// Hack for buildDependencies
|
|
164
|
+
const rawResolveBuildDependencies = FileSystemInfo.prototype.resolveBuildDependencies
|
|
165
|
+
FileSystemInfo.prototype.resolveBuildDependencies = function (context, deps, rawCallback) {
|
|
166
|
+
return rawResolveBuildDependencies.call(this, context, deps, (err, result) => {
|
|
167
|
+
if (result && typeof options.hackResolveBuildDependencies === 'function') options.hackResolveBuildDependencies(result)
|
|
168
|
+
return rawCallback(err, result)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
162
171
|
}
|
|
163
172
|
|
|
164
173
|
static loader (options = {}) {
|
|
@@ -1300,10 +1309,11 @@ try {
|
|
|
1300
1309
|
let insertBeforeIndex = -1
|
|
1301
1310
|
const info = typeLoaderProcessInfo[type]
|
|
1302
1311
|
loaders.forEach((loader, index) => {
|
|
1303
|
-
|
|
1312
|
+
const currentLoader = toPosix(loader.loader)
|
|
1313
|
+
if (currentLoader.includes(info[0])) {
|
|
1304
1314
|
loader.loader = info[1]
|
|
1305
|
-
|
|
1306
|
-
if (
|
|
1315
|
+
insertBeforeIndex = index
|
|
1316
|
+
} else if (currentLoader.includes(info[1])) {
|
|
1307
1317
|
insertBeforeIndex = index
|
|
1308
1318
|
}
|
|
1309
1319
|
})
|
|
@@ -1343,13 +1353,13 @@ try {
|
|
|
1343
1353
|
|
|
1344
1354
|
if (mpx.mode === 'web') {
|
|
1345
1355
|
const mpxStyleOptions = queryObj.mpxStyleOptions
|
|
1346
|
-
const firstLoader = (loaders[0] && loaders[0].loader) || ''
|
|
1356
|
+
const firstLoader = toPosix(loaders[0] && loaders[0].loader) || ''
|
|
1347
1357
|
const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
|
|
1348
1358
|
let cssLoaderIndex = -1
|
|
1349
1359
|
let vueStyleLoaderIndex = -1
|
|
1350
1360
|
let mpxStyleLoaderIndex = -1
|
|
1351
1361
|
loaders.forEach((loader, index) => {
|
|
1352
|
-
const currentLoader = loader.loader
|
|
1362
|
+
const currentLoader = toPosix(loader.loader)
|
|
1353
1363
|
if (currentLoader.includes('css-loader')) {
|
|
1354
1364
|
cssLoaderIndex = index
|
|
1355
1365
|
} else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader')) {
|
package/lib/loader.js
CHANGED
|
@@ -3,7 +3,7 @@ const parseComponent = require('./parser')
|
|
|
3
3
|
const createHelpers = require('./helpers')
|
|
4
4
|
const loaderUtils = require('loader-utils')
|
|
5
5
|
const parseRequest = require('./utils/parse-request')
|
|
6
|
-
const matchCondition = require('./utils/match-condition')
|
|
6
|
+
const { matchCondition } = require('./utils/match-condition')
|
|
7
7
|
const fixUsingComponent = require('./utils/fix-using-component')
|
|
8
8
|
const addQuery = require('./utils/add-query')
|
|
9
9
|
const async = require('async')
|
package/lib/native-loader.js
CHANGED
|
@@ -5,7 +5,7 @@ const config = require('./config')
|
|
|
5
5
|
const createHelpers = require('./helpers')
|
|
6
6
|
const getJSONContent = require('./utils/get-json-content')
|
|
7
7
|
const async = require('async')
|
|
8
|
-
const matchCondition = require('./utils/match-condition')
|
|
8
|
+
const { matchCondition } = require('./utils/match-condition')
|
|
9
9
|
const fixUsingComponent = require('./utils/fix-using-component')
|
|
10
10
|
const { JSON_JS_EXT } = require('./utils/const')
|
|
11
11
|
|
|
@@ -2,7 +2,7 @@ const path = require('path')
|
|
|
2
2
|
const stringifyQuery = require('../utils/stringify-query')
|
|
3
3
|
const parseQuery = require('loader-utils').parseQuery
|
|
4
4
|
const addInfix = require('../utils/add-infix')
|
|
5
|
-
const matchCondition = require('../utils/match-condition')
|
|
5
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
6
6
|
const { JSON_JS_EXT } = require('../utils/const')
|
|
7
7
|
|
|
8
8
|
module.exports = class AddEnvPlugin {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const stringifyQuery = require('../utils/stringify-query')
|
|
3
3
|
const parseQuery = require('loader-utils').parseQuery
|
|
4
|
-
const matchCondition = require('../utils/match-condition')
|
|
4
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
5
5
|
const addInfix = require('../utils/add-infix')
|
|
6
6
|
const { JSON_JS_EXT } = require('../utils/const')
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import getInnerListeners from './getInnerListeners'
|
|
2
|
+
import getInnerListeners, { extendEvent } from './getInnerListeners'
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
name: 'mpx-image',
|
|
@@ -23,6 +23,13 @@
|
|
|
23
23
|
beforeCreate () {
|
|
24
24
|
this.image = new Image()
|
|
25
25
|
this.image.onload = (e) => {
|
|
26
|
+
extendEvent(e, {
|
|
27
|
+
detail: {
|
|
28
|
+
width: this.image.width,
|
|
29
|
+
height: this.image.height
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
26
33
|
this.$emit('load', e)
|
|
27
34
|
}
|
|
28
35
|
this.image.onerror = (e) => {
|
|
@@ -7,7 +7,7 @@ const vw = require('./plugins/vw')
|
|
|
7
7
|
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
8
8
|
const scopeId = require('./plugins/scope-id')
|
|
9
9
|
const transSpecial = require('./plugins/trans-special')
|
|
10
|
-
const matchCondition = require('../utils/match-condition')
|
|
10
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
11
11
|
const parseRequest = require('../utils/parse-request')
|
|
12
12
|
|
|
13
13
|
module.exports = function (css, map) {
|
|
@@ -16,7 +16,9 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
16
16
|
webpack: loaderContext,
|
|
17
17
|
defs: inlineConfig.defs || {}
|
|
18
18
|
}
|
|
19
|
-
loaded = load(ctx, config.path, {
|
|
19
|
+
loaded = load(ctx, config.path, {
|
|
20
|
+
loaders: { '.json': (_, content) => JSON.parse(content) }
|
|
21
|
+
}).catch(err => {
|
|
20
22
|
// postcss-load-config throws error when no config file is found,
|
|
21
23
|
// but for us it's optional. only emit other errors
|
|
22
24
|
if (err.message.indexOf('No PostCSS Config found') >= 0) {
|
|
@@ -3,6 +3,7 @@ const he = require('he')
|
|
|
3
3
|
const config = require('../config')
|
|
4
4
|
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
5
5
|
const normalize = require('../utils/normalize')
|
|
6
|
+
const { normalizeCondition } = require('../utils/match-condition')
|
|
6
7
|
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
7
8
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
9
|
const getRulesRunner = require('../platform/index')
|
|
@@ -10,7 +11,6 @@ const addQuery = require('../utils/add-query')
|
|
|
10
11
|
const transDynamicClassExpr = require('./trans-dynamic-class-expr')
|
|
11
12
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
12
13
|
const { inBrowser } = require('../utils/env')
|
|
13
|
-
|
|
14
14
|
/**
|
|
15
15
|
* Make a map and return a function for checking if a key
|
|
16
16
|
* is in that map.
|
|
@@ -737,8 +737,10 @@ function parse (template, options) {
|
|
|
737
737
|
|
|
738
738
|
currentParent.children.push(element)
|
|
739
739
|
element.parent = currentParent
|
|
740
|
-
|
|
741
740
|
processElement(element, root, options, meta)
|
|
741
|
+
if (isComponentNode(element, options) && mode === 'ali' && !options.hasVirtualHost) {
|
|
742
|
+
processAliAddComponentRootView(element, options, stack, currentParent)
|
|
743
|
+
}
|
|
742
744
|
tagNames.add(element.tag)
|
|
743
745
|
|
|
744
746
|
if (!unary) {
|
|
@@ -1800,36 +1802,70 @@ function processBuiltInComponents (el, meta) {
|
|
|
1800
1802
|
}
|
|
1801
1803
|
}
|
|
1802
1804
|
|
|
1803
|
-
function
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1805
|
+
function processAliAddComponentRootView (el, options, stack, currentParent) {
|
|
1806
|
+
const processAttrsConditions = [
|
|
1807
|
+
{ condition: /^(on|catch)Tap$/, action: 'clone' },
|
|
1808
|
+
{ condition: /^(on|catch)TouchStart$/, action: 'clone' },
|
|
1809
|
+
{ condition: /^(on|catch)TouchMove$/, action: 'clone' },
|
|
1810
|
+
{ condition: /^(on|catch)TouchEnd$/, action: 'clone' },
|
|
1811
|
+
{ condition: /^(on|catch)TouchCancel$/, action: 'clone' },
|
|
1812
|
+
{ condition: /^(on|catch)LongTap$/, action: 'clone' },
|
|
1813
|
+
{ condition: /^data-/, action: 'clone' },
|
|
1814
|
+
{ condition: 'style', action: 'move' },
|
|
1815
|
+
{ condition: 'class', action: 'append', value: `${MPX_ROOT_VIEW} host-${options.moduleId}` }
|
|
1816
|
+
]
|
|
1817
|
+
let newElAttrs = []
|
|
1818
|
+
let allAttrs = cloneAttrsList(el.attrsList)
|
|
1819
|
+
|
|
1820
|
+
function processClone (attr) {
|
|
1821
|
+
newElAttrs.push(attr)
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
function processMove (attr) {
|
|
1825
|
+
let movedAttr = getAndRemoveAttr(el, attr.name)
|
|
1826
|
+
if (movedAttr.has) {
|
|
1827
|
+
newElAttrs.push({
|
|
1828
|
+
name: attr,
|
|
1829
|
+
value: movedAttr.val
|
|
1830
|
+
})
|
|
1813
1831
|
}
|
|
1814
1832
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
let typeName = 'mpx' + type.replace(/^./, (matched) => matched.toUpperCase())
|
|
1821
|
-
let [newName, newValue] = processor({
|
|
1822
|
-
name: type,
|
|
1823
|
-
value: exp,
|
|
1824
|
-
typeName
|
|
1825
|
-
})
|
|
1826
|
-
if (newValue !== undefined) {
|
|
1827
|
-
addAttrs(el, [{
|
|
1828
|
-
name: newName,
|
|
1829
|
-
value: newValue
|
|
1830
|
-
}])
|
|
1833
|
+
|
|
1834
|
+
function processAppend (attr, item) {
|
|
1835
|
+
const getNeedAppendAttrValue = el.attrsMap[attr.name]
|
|
1836
|
+
if (getNeedAppendAttrValue) {
|
|
1837
|
+
item.value = getNeedAppendAttrValue + ' ' + item.value
|
|
1831
1838
|
}
|
|
1839
|
+
newElAttrs.push({
|
|
1840
|
+
name: attr.name,
|
|
1841
|
+
value: item.value
|
|
1842
|
+
})
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
processAttrsConditions.forEach(item => {
|
|
1846
|
+
const matcher = normalizeCondition(item.condition)
|
|
1847
|
+
allAttrs.forEach((attr) => {
|
|
1848
|
+
if (matcher(attr.name)) {
|
|
1849
|
+
if (item.action === 'clone') {
|
|
1850
|
+
processClone(attr)
|
|
1851
|
+
} else if (item.action === 'move') {
|
|
1852
|
+
processMove(attr)
|
|
1853
|
+
} else if (item.action === 'append') {
|
|
1854
|
+
processAppend(attr, item)
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
})
|
|
1832
1858
|
})
|
|
1859
|
+
|
|
1860
|
+
// create new el
|
|
1861
|
+
let componentWrapView = createASTElement('view', newElAttrs)
|
|
1862
|
+
currentParent.children.pop()
|
|
1863
|
+
currentParent.children.push(componentWrapView)
|
|
1864
|
+
componentWrapView.parent = currentParent
|
|
1865
|
+
componentWrapView.children.push(el)
|
|
1866
|
+
el.parent = componentWrapView
|
|
1867
|
+
|
|
1868
|
+
el = componentWrapView
|
|
1833
1869
|
}
|
|
1834
1870
|
|
|
1835
1871
|
// 有virtualHost情况wx组件注入virtualHost。无virtualHost阿里组件注入root-view。其他跳过。
|
|
@@ -1841,17 +1877,17 @@ function getVirtualHostRoot (options, meta) {
|
|
|
1841
1877
|
!meta.options && (meta.options = {})
|
|
1842
1878
|
meta.options.virtualHost = true
|
|
1843
1879
|
}
|
|
1844
|
-
if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
}
|
|
1880
|
+
// if (mode === 'ali' && !options.hasVirtualHost) {
|
|
1881
|
+
// // ali组件根节点实体化
|
|
1882
|
+
// let rootView = createASTElement('view', [
|
|
1883
|
+
// {
|
|
1884
|
+
// name: 'class',
|
|
1885
|
+
// value: `${MPX_ROOT_VIEW} host-${options.moduleId}`
|
|
1886
|
+
// }
|
|
1887
|
+
// ])
|
|
1888
|
+
// processElement(rootView, rootView, options, meta)
|
|
1889
|
+
// return rootView
|
|
1890
|
+
// }
|
|
1855
1891
|
}
|
|
1856
1892
|
return getTempNode()
|
|
1857
1893
|
}
|
|
@@ -2060,11 +2096,6 @@ function processElement (el, root, options, meta) {
|
|
|
2060
2096
|
processShow(el, options, root)
|
|
2061
2097
|
}
|
|
2062
2098
|
|
|
2063
|
-
// 当mode为ali不管是不是跨平台都需要进行此处理,以保障ali当中的refs相关增强能力正常运行
|
|
2064
|
-
if (mode === 'ali') {
|
|
2065
|
-
processAliStyleClassHack(el, options, root)
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
2099
|
if (!pass) {
|
|
2069
2100
|
processBindEvent(el, options)
|
|
2070
2101
|
processComponentIs(el, options)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const compiler = require('./compiler')
|
|
2
2
|
const bindThis = require('./bind-this').transform
|
|
3
3
|
const parseRequest = require('../utils/parse-request')
|
|
4
|
-
const matchCondition = require('../utils/match-condition')
|
|
4
|
+
const { matchCondition } = require('../utils/match-condition')
|
|
5
5
|
const loaderUtils = require('loader-utils')
|
|
6
6
|
|
|
7
7
|
module.exports = function (raw) {
|
|
@@ -2,8 +2,7 @@ const templateCompiler = require('../template-compiler/compiler')
|
|
|
2
2
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
4
|
const parseRequest = require('../utils/parse-request')
|
|
5
|
-
|
|
6
|
-
// const matchCondition = require('../utils/match-condition')
|
|
5
|
+
// const { matchCondition } = require('../utils/match-condition')
|
|
7
6
|
|
|
8
7
|
function calculateRootEleChild (arr) {
|
|
9
8
|
if (!arr) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.13",
|
|
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": "
|
|
83
|
+
"gitHead": "be0a3699bcc617e76ffa6a27c0925da157335033"
|
|
84
84
|
}
|