@mpxjs/webpack-plugin 2.7.0-beta.4 → 2.7.0-beta.8
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/dependencies/CommonJsVariableDependency.js +1 -3
- package/lib/dependencies/DynamicEntryDependency.js +2 -1
- package/lib/dependencies/{RecordStaticResourceDependency.js → RecordResourceMapDependency.js} +12 -7
- package/lib/dependencies/ResolveDependency.js +8 -7
- package/lib/extractor.js +4 -4
- package/lib/file-loader.js +2 -2
- package/lib/index.js +154 -118
- package/lib/json-compiler/helper.js +14 -11
- package/lib/json-compiler/index.js +19 -13
- package/lib/loader.js +27 -36
- package/lib/platform/json/wx/index.js +7 -2
- package/lib/platform/template/wx/component-config/button.js +3 -3
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/web/getInnerListeners.js +51 -45
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/optionProcessor.js +5 -20
- package/lib/runtime/stringify.wxs +3 -3
- package/lib/style-compiler/index.js +4 -5
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +100 -36
- package/lib/template-compiler/index.js +3 -6
- package/lib/template-compiler/trans-dynamic-class-expr.js +3 -3
- package/lib/utils/const.js +3 -1
- package/lib/web/processJSON.js +105 -113
- package/lib/web/processScript.js +30 -24
- package/lib/web/processTemplate.js +56 -37
- package/lib/wxs/loader.js +24 -27
- package/lib/wxs/pre-loader.js +4 -4
- package/lib/wxss/processCss.js +44 -44
- package/package.json +8 -8
- package/lib/built-in-loader.js +0 -45
- package/lib/record-loader.js +0 -11
package/lib/web/processScript.js
CHANGED
|
@@ -2,7 +2,6 @@ const genComponentTag = require('../utils/gen-component-tag')
|
|
|
2
2
|
const loaderUtils = require('loader-utils')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
4
|
const normalize = require('../utils/normalize')
|
|
5
|
-
const builtInLoaderPath = normalize.lib('built-in-loader')
|
|
6
5
|
const optionProcessorPath = normalize.lib('runtime/optionProcessor')
|
|
7
6
|
const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
|
|
8
7
|
const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
|
|
@@ -21,23 +20,29 @@ function shallowStringify (obj) {
|
|
|
21
20
|
return `{${arr.join(',')}}`
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
module.exports = function (script,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
module.exports = function (script, {
|
|
24
|
+
loaderContext,
|
|
25
|
+
ctorType,
|
|
26
|
+
srcMode,
|
|
27
|
+
isProduction,
|
|
28
|
+
componentGenerics,
|
|
29
|
+
jsonConfig,
|
|
30
|
+
outputPath,
|
|
31
|
+
tabBarMap,
|
|
32
|
+
tabBarStr,
|
|
33
|
+
builtInComponentsMap,
|
|
34
|
+
genericsInfo,
|
|
35
|
+
wxsModuleMap,
|
|
36
|
+
localComponentsMap,
|
|
37
|
+
localPagesMap
|
|
38
|
+
}, callback) {
|
|
39
|
+
const mpx = loaderContext.getMpx()
|
|
40
|
+
const {
|
|
41
|
+
i18n,
|
|
42
|
+
projectRoot
|
|
43
|
+
} = mpx
|
|
44
|
+
|
|
35
45
|
const tabBar = jsonConfig.tabBar
|
|
36
|
-
const tabBarMap = options.tabBarMap
|
|
37
|
-
const tabBarStr = options.tabBarStr
|
|
38
|
-
const genericsInfo = options.genericsInfo
|
|
39
|
-
const componentGenerics = options.componentGenerics
|
|
40
|
-
const forceDisableBuiltInLoader = options.forceDisableBuiltInLoader
|
|
41
46
|
|
|
42
47
|
const emitWarning = (msg) => {
|
|
43
48
|
loaderContext.emitWarning(
|
|
@@ -49,7 +54,7 @@ module.exports = function (script, options, callback) {
|
|
|
49
54
|
let tabBarPagesMap = {}
|
|
50
55
|
if (tabBar && tabBarMap) {
|
|
51
56
|
// 挂载tabBar组件
|
|
52
|
-
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, {
|
|
57
|
+
const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
|
|
53
58
|
tabBarPagesMap['mpx-tab-bar'] = `getComponent(require(${tabBarRequest}))`
|
|
54
59
|
// 挂载tabBar页面
|
|
55
60
|
Object.keys(tabBarMap).forEach((pagePath) => {
|
|
@@ -161,9 +166,9 @@ module.exports = function (script, options, callback) {
|
|
|
161
166
|
}
|
|
162
167
|
// 注入wxs模块
|
|
163
168
|
content += ' const wxsModules = {}\n'
|
|
164
|
-
if (
|
|
165
|
-
Object.keys(
|
|
166
|
-
const src = loaderUtils.urlToRequest(
|
|
169
|
+
if (wxsModuleMap) {
|
|
170
|
+
Object.keys(wxsModuleMap).forEach((module) => {
|
|
171
|
+
const src = loaderUtils.urlToRequest(wxsModuleMap[module], projectRoot)
|
|
167
172
|
const expression = `require(${stringifyRequest(src)})`
|
|
168
173
|
content += ` wxsModules.${module} = ${expression}\n`
|
|
169
174
|
})
|
|
@@ -202,7 +207,7 @@ module.exports = function (script, options, callback) {
|
|
|
202
207
|
|
|
203
208
|
Object.keys(builtInComponentsMap).forEach((componentName) => {
|
|
204
209
|
const componentCfg = builtInComponentsMap[componentName]
|
|
205
|
-
const componentRequest =
|
|
210
|
+
const componentRequest = stringifyRequest(componentCfg.resource)
|
|
206
211
|
componentsMap[componentName] = `getComponent(require(${componentRequest}), { __mpxBuiltIn: true })`
|
|
207
212
|
})
|
|
208
213
|
|
|
@@ -211,10 +216,11 @@ module.exports = function (script, options, callback) {
|
|
|
211
216
|
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
212
217
|
}
|
|
213
218
|
// 为了正确获取currentSrcMode便于运行时进行转换,对于src引入的组件script采用require方式引入(由于webpack会将import的执行顺序上升至最顶),这意味着对于src引入脚本中的named export将不会生效,不过鉴于mpx和小程序中本身也没有在组件script中声明export的用法,所以应该没有影响
|
|
219
|
+
content += '\n\n\n/** ====== Source start ====== **/\n'
|
|
214
220
|
content += script.src
|
|
215
221
|
? `require(${stringifyRequest(script.src)})\n`
|
|
216
222
|
: script.content
|
|
217
|
-
content += '\n'
|
|
223
|
+
content += '\n/** ====== Source end ====== **/\n\n\n'
|
|
218
224
|
// createApp/Page/Component执行完成后立刻获取当前的option并暂存
|
|
219
225
|
content += ` const currentOption = global.currentOption\n`
|
|
220
226
|
// 获取pageConfig
|
|
@@ -245,7 +251,7 @@ module.exports = function (script, options, callback) {
|
|
|
245
251
|
currentOption,
|
|
246
252
|
${JSON.stringify(ctorType)},
|
|
247
253
|
${JSON.stringify(firstPage)},
|
|
248
|
-
${JSON.stringify(
|
|
254
|
+
${JSON.stringify(outputPath)},
|
|
249
255
|
${JSON.stringify(pageConfig)},
|
|
250
256
|
// @ts-ignore
|
|
251
257
|
${shallowStringify(pagesMap)},
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const templateCompiler = require('../template-compiler/compiler')
|
|
2
2
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
|
-
const path = require('path')
|
|
5
4
|
const parseRequest = require('../utils/parse-request')
|
|
6
5
|
|
|
6
|
+
// const matchCondition = require('../utils/match-condition')
|
|
7
|
+
|
|
7
8
|
function calculateRootEleChild (arr) {
|
|
8
9
|
if (!arr) {
|
|
9
10
|
return 0
|
|
@@ -20,17 +21,30 @@ function calculateRootEleChild (arr) {
|
|
|
20
21
|
}, 0)
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
module.exports = function (template,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
module.exports = function (template, {
|
|
25
|
+
loaderContext,
|
|
26
|
+
// hasScoped,
|
|
27
|
+
hasComment,
|
|
28
|
+
isNative,
|
|
29
|
+
srcMode,
|
|
30
|
+
moduleId,
|
|
31
|
+
ctorType,
|
|
32
|
+
usingComponents,
|
|
33
|
+
componentGenerics
|
|
34
|
+
}, callback) {
|
|
32
35
|
const mpx = loaderContext.getMpx()
|
|
33
|
-
const
|
|
36
|
+
const {
|
|
37
|
+
mode,
|
|
38
|
+
defs,
|
|
39
|
+
wxsContentMap,
|
|
40
|
+
decodeHTMLText,
|
|
41
|
+
externalClasses,
|
|
42
|
+
checkUsingComponents
|
|
43
|
+
// autoVirtualHostRules
|
|
44
|
+
} = mpx
|
|
45
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
46
|
+
const builtInComponentsMap = {}
|
|
47
|
+
|
|
34
48
|
let wxsModuleMap, genericsInfo
|
|
35
49
|
let output = '/* template */\n'
|
|
36
50
|
|
|
@@ -40,7 +54,7 @@ module.exports = function (template, options, callback) {
|
|
|
40
54
|
content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
|
|
41
55
|
}
|
|
42
56
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
43
|
-
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', {
|
|
57
|
+
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
60
|
|
|
@@ -59,7 +73,7 @@ module.exports = function (template, options, callback) {
|
|
|
59
73
|
}
|
|
60
74
|
if (template.content) {
|
|
61
75
|
const templateSrcMode = template.mode || srcMode
|
|
62
|
-
const
|
|
76
|
+
const { root, meta } = templateCompiler.parse(template.content, {
|
|
63
77
|
warn: (msg) => {
|
|
64
78
|
loaderContext.emitWarning(
|
|
65
79
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
@@ -70,54 +84,59 @@ module.exports = function (template, options, callback) {
|
|
|
70
84
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
71
85
|
)
|
|
72
86
|
},
|
|
73
|
-
usingComponents
|
|
74
|
-
hasComment
|
|
75
|
-
isNative
|
|
76
|
-
basename: path.basename(resourcePath),
|
|
87
|
+
usingComponents,
|
|
88
|
+
hasComment,
|
|
89
|
+
isNative,
|
|
77
90
|
isComponent: ctorType === 'component',
|
|
78
91
|
mode,
|
|
79
92
|
srcMode: templateSrcMode,
|
|
80
93
|
defs,
|
|
81
|
-
decodeHTMLText
|
|
82
|
-
externalClasses
|
|
94
|
+
decodeHTMLText,
|
|
95
|
+
externalClasses,
|
|
83
96
|
// todo 后续输出web也采用mpx的scoped处理
|
|
84
|
-
// hasScoped:options.hasScoped,
|
|
85
97
|
hasScoped: false,
|
|
86
98
|
moduleId,
|
|
87
99
|
filePath: loaderContext.resourcePath,
|
|
88
100
|
i18n: null,
|
|
89
|
-
checkUsingComponents
|
|
101
|
+
checkUsingComponents,
|
|
90
102
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
91
103
|
globalComponents: [],
|
|
92
104
|
// web模式下实现抽象组件
|
|
93
|
-
componentGenerics
|
|
105
|
+
componentGenerics
|
|
106
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
107
|
+
// hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
94
108
|
})
|
|
95
|
-
if (
|
|
96
|
-
wxsModuleMap =
|
|
109
|
+
if (meta.wxsModuleMap) {
|
|
110
|
+
wxsModuleMap = meta.wxsModuleMap
|
|
97
111
|
}
|
|
98
|
-
if (
|
|
99
|
-
for (let module in
|
|
100
|
-
wxsContentMap[`${resourcePath}~${module}`] =
|
|
112
|
+
if (meta.wxsContentMap) {
|
|
113
|
+
for (let module in meta.wxsContentMap) {
|
|
114
|
+
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
|
-
if (
|
|
104
|
-
Object.keys(
|
|
117
|
+
if (meta.builtInComponentsMap) {
|
|
118
|
+
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
105
119
|
builtInComponentsMap[name] = {
|
|
106
|
-
resource: addQuery(
|
|
120
|
+
resource: addQuery(meta.builtInComponentsMap[name], { isComponent: true })
|
|
107
121
|
}
|
|
108
122
|
})
|
|
109
123
|
}
|
|
110
|
-
if (
|
|
111
|
-
genericsInfo =
|
|
124
|
+
if (meta.genericsInfo) {
|
|
125
|
+
genericsInfo = meta.genericsInfo
|
|
112
126
|
}
|
|
113
|
-
// 输出H5有多个root element时, 使用
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
// 输出H5有多个root element时, 使用mpx-root-view标签包裹
|
|
128
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
129
|
+
if (root.tag === 'temp-node') {
|
|
130
|
+
const childLen = calculateRootEleChild(root.children)
|
|
116
131
|
if (childLen >= 2) {
|
|
117
|
-
|
|
132
|
+
root.tag = 'div'
|
|
133
|
+
templateCompiler.addAttrs(root, [{
|
|
134
|
+
name: 'class',
|
|
135
|
+
value: 'mpx-root-view'
|
|
136
|
+
}])
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
|
-
return templateCompiler.serialize(
|
|
139
|
+
return templateCompiler.serialize(root)
|
|
121
140
|
}
|
|
122
141
|
})
|
|
123
142
|
output += '\n\n'
|
package/lib/wxs/loader.js
CHANGED
|
@@ -3,7 +3,7 @@ const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
|
3
3
|
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const WxsPlugin = require('./WxsPlugin')
|
|
6
|
-
const
|
|
6
|
+
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
7
7
|
const parseRequest = require('../utils/parse-request')
|
|
8
8
|
const toPosix = require('../utils/to-posix')
|
|
9
9
|
const fixRelative = require('../utils/fix-relative')
|
|
@@ -14,8 +14,7 @@ module.exports = function () {
|
|
|
14
14
|
const moduleGraph = this._compilation.moduleGraph
|
|
15
15
|
const mpx = this.getMpx()
|
|
16
16
|
const mode = mpx.mode
|
|
17
|
-
const
|
|
18
|
-
const appInfo = mpx.appInfo
|
|
17
|
+
const getOutputPath = mpx.getOutputPath
|
|
19
18
|
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
20
19
|
const issuer = moduleGraph.getIssuer(this._module)
|
|
21
20
|
const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || issuer.resource)
|
|
@@ -23,7 +22,7 @@ module.exports = function () {
|
|
|
23
22
|
const pagesMap = mpx.pagesMap
|
|
24
23
|
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
25
24
|
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
26
|
-
const issuerName =
|
|
25
|
+
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
27
26
|
const issuerDir = path.dirname(issuerName)
|
|
28
27
|
|
|
29
28
|
const getName = (raw) => {
|
|
@@ -36,9 +35,9 @@ module.exports = function () {
|
|
|
36
35
|
resourcePath = `${resourcePath}~${wxsModule}`
|
|
37
36
|
}
|
|
38
37
|
const packageRoot = queryObj.packageRoot || ''
|
|
39
|
-
const
|
|
40
|
-
const filename = toPosix(path.join(packageRoot,
|
|
41
|
-
this._module.addPresentationalDependency(new
|
|
38
|
+
const ext = config[mode].wxs.ext
|
|
39
|
+
const filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
|
|
40
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', filename, packageRoot))
|
|
42
41
|
|
|
43
42
|
const callback = (err) => {
|
|
44
43
|
if (err) return nativeCallback(err)
|
|
@@ -47,18 +46,25 @@ module.exports = function () {
|
|
|
47
46
|
nativeCallback(null, `module.exports = ${JSON.stringify(relativePath)};`)
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
if (wxsMap[filename]) {
|
|
51
|
-
wxsMap[filename].modules.push(this._module)
|
|
52
|
-
return callback()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
wxsMap[filename] = {
|
|
56
|
-
dep: null,
|
|
57
|
-
modules: [this._module]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
const outputOptions = {
|
|
61
|
-
filename
|
|
50
|
+
filename,
|
|
51
|
+
// 避免输出的wxs中包含es语法
|
|
52
|
+
environment: {
|
|
53
|
+
// The environment supports arrow functions ('() => { ... }').
|
|
54
|
+
arrowFunction: false,
|
|
55
|
+
// The environment supports BigInt as literal (123n).
|
|
56
|
+
bigIntLiteral: false,
|
|
57
|
+
// The environment supports const and let for variable declarations.
|
|
58
|
+
const: false,
|
|
59
|
+
// The environment supports destructuring ('{ a, b } = obj').
|
|
60
|
+
destructuring: false,
|
|
61
|
+
// The environment supports an async import() function to import EcmaScript modules.
|
|
62
|
+
dynamicImport: false,
|
|
63
|
+
// The environment supports 'for of' iteration ('for (const x of array) { ... }').
|
|
64
|
+
forOf: false,
|
|
65
|
+
// The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
|
|
66
|
+
module: false
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
// wxs文件必须经过pre-loader
|
|
64
70
|
const request = '!!' + this.remainingRequest
|
|
@@ -71,15 +77,6 @@ module.exports = function () {
|
|
|
71
77
|
|
|
72
78
|
const childCompiler = this._compilation.createChildCompiler(resourcePath, outputOptions, plugins)
|
|
73
79
|
|
|
74
|
-
// let entryModule
|
|
75
|
-
// childCompiler.hooks.thisCompilation.tap('MpxWebpackPlugin ', (compilation) => {
|
|
76
|
-
// compilation.hooks.succeedEntry.tap('MpxWebpackPlugin', (entry, name, module) => {
|
|
77
|
-
// entryModule = module
|
|
78
|
-
// // const dep = new ChildCompileDependency(entryModule)
|
|
79
|
-
// // wxsMap[filename].dep = dep
|
|
80
|
-
// })
|
|
81
|
-
// })
|
|
82
|
-
|
|
83
80
|
childCompiler.hooks.afterCompile.tap('MpxWebpackPlugin', (compilation) => {
|
|
84
81
|
// 持久化缓存,使用module.buildInfo.assets来输出文件
|
|
85
82
|
compilation.getAssets().forEach(({ name, source, info }) => {
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const babylon = require('
|
|
2
|
-
const traverse = require('babel
|
|
3
|
-
const t = require('babel
|
|
4
|
-
const generate = require('babel
|
|
1
|
+
const babylon = require('@babel/parser')
|
|
2
|
+
const traverse = require('@babel/traverse').default
|
|
3
|
+
const t = require('@babel/types')
|
|
4
|
+
const generate = require('@babel/generator').default
|
|
5
5
|
const parseRequest = require('../utils/parse-request')
|
|
6
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
7
7
|
const parseQuery = require('loader-utils').parseQuery
|
package/lib/wxss/processCss.js
CHANGED
|
@@ -3,37 +3,37 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
Modified by @hiyuki
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const formatCodeFrame = require('@babel/code-frame')
|
|
7
|
+
const Tokenizer = require('css-selector-tokenizer')
|
|
8
|
+
const postcss = require('postcss')
|
|
9
|
+
const loaderUtils = require('loader-utils')
|
|
10
|
+
const assign = require('object-assign')
|
|
11
|
+
const getLocalIdent = require('./getLocalIdent')
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const icssUtils = require('icss-utils')
|
|
14
|
+
const localByDefault = require('postcss-modules-local-by-default')
|
|
15
|
+
const extractImports = require('postcss-modules-extract-imports')
|
|
16
|
+
const modulesScope = require('postcss-modules-scope')
|
|
17
|
+
const modulesValues = require('postcss-modules-values')
|
|
18
|
+
const valueParser = require('postcss-value-parser')
|
|
19
|
+
const isUrlRequest = require('../utils/is-url-request')
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
22
22
|
return function (css) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const imports = {}
|
|
24
|
+
let exports = {}
|
|
25
|
+
const importItems = []
|
|
26
|
+
const urlItems = []
|
|
27
27
|
|
|
28
28
|
function replaceImportsInString (str) {
|
|
29
29
|
if (options.import) {
|
|
30
|
-
|
|
30
|
+
const tokens = valueParser(str)
|
|
31
31
|
tokens.walk(function (node) {
|
|
32
32
|
if (node.type !== 'word') {
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const token = node.value
|
|
36
|
+
const importIndex = imports['$' + token]
|
|
37
37
|
if (typeof importIndex === 'number') {
|
|
38
38
|
node.value = '___CSS_LOADER_IMPORT___' + importIndex + '___'
|
|
39
39
|
}
|
|
@@ -45,8 +45,8 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
45
45
|
|
|
46
46
|
if (options.import) {
|
|
47
47
|
css.walkAtRules(/^import$/i, function (rule) {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const values = Tokenizer.parseValues(rule.params)
|
|
49
|
+
let url = values.nodes[0].nodes[0]
|
|
50
50
|
if (url && url.type === 'url') {
|
|
51
51
|
url = url.url
|
|
52
52
|
} else if (url && url.type === 'string') {
|
|
@@ -56,7 +56,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
values.nodes[0].nodes.shift()
|
|
59
|
-
|
|
59
|
+
const mediaQuery = Tokenizer.stringifyValues(values)
|
|
60
60
|
|
|
61
61
|
if (isUrlRequest(url, options.root)) {
|
|
62
62
|
url = loaderUtils.urlToRequest(url, options.root)
|
|
@@ -70,10 +70,10 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
70
70
|
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
const icss = icssUtils.extractICSS(css)
|
|
74
74
|
exports = icss.icssExports
|
|
75
75
|
Object.keys(icss.icssImports).forEach(function (key) {
|
|
76
|
-
|
|
76
|
+
const url = loaderUtils.parseString(key)
|
|
77
77
|
Object.keys(icss.icssImports[key]).forEach(function (prop) {
|
|
78
78
|
imports['$' + prop] = importItems.length
|
|
79
79
|
importItems.push({
|
|
@@ -101,7 +101,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
101
101
|
item.nodes.forEach(processNode)
|
|
102
102
|
break
|
|
103
103
|
case 'item':
|
|
104
|
-
|
|
104
|
+
const importIndex = imports['$' + item.name]
|
|
105
105
|
if (typeof importIndex === 'number') {
|
|
106
106
|
item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
|
|
107
107
|
}
|
|
@@ -112,7 +112,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
112
112
|
item.stringType = ''
|
|
113
113
|
delete item.innerSpacingBefore
|
|
114
114
|
delete item.innerSpacingAfter
|
|
115
|
-
|
|
115
|
+
const url = item.url
|
|
116
116
|
item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
|
|
117
117
|
urlItems.push({
|
|
118
118
|
url: url
|
|
@@ -123,7 +123,7 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
css.walkDecls(function (decl) {
|
|
126
|
-
|
|
126
|
+
const values = Tokenizer.parseValues(decl.value)
|
|
127
127
|
values.nodes.forEach(function (value) {
|
|
128
128
|
value.nodes.forEach(processNode)
|
|
129
129
|
})
|
|
@@ -142,17 +142,17 @@ var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
|
|
|
142
142
|
})
|
|
143
143
|
|
|
144
144
|
module.exports = function processCss (inputSource, inputMap, options, callback) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
const query = options.query
|
|
146
|
+
const root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
|
|
147
|
+
const context = query.context
|
|
148
|
+
const localIdentName = query.localIdentName || '[hash:base64]'
|
|
149
|
+
const localIdentRegExp = query.localIdentRegExp
|
|
150
|
+
const forceMinimize = query.minimize
|
|
151
|
+
const minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
const customGetLocalIdent = query.getLocalIdent || getLocalIdent
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
const parserOptions = {
|
|
156
156
|
root: root,
|
|
157
157
|
mode: options.mode,
|
|
158
158
|
url: query.url !== false,
|
|
@@ -160,7 +160,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
|
|
|
160
160
|
resolve: options.resolve
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
const pipeline = postcss([
|
|
164
164
|
modulesValues,
|
|
165
165
|
localByDefault({
|
|
166
166
|
mode: options.mode,
|
|
@@ -192,8 +192,8 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
|
|
|
192
192
|
])
|
|
193
193
|
|
|
194
194
|
if (minimize) {
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
const cssnano = require('cssnano')
|
|
196
|
+
const minimizeOptions = assign({}, query.minimize);
|
|
197
197
|
['zindex', 'normalizeUrl', 'discardUnused', 'mergeIdents', 'reduceIdents', 'autoprefixer', 'svgo'].forEach(function (name) {
|
|
198
198
|
if (typeof minimizeOptions[name] === 'undefined') {
|
|
199
199
|
minimizeOptions[name] = false
|
|
@@ -226,7 +226,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
|
|
|
226
226
|
})
|
|
227
227
|
}).catch(function (err) {
|
|
228
228
|
if (err.name === 'CssSyntaxError') {
|
|
229
|
-
|
|
229
|
+
const wrappedError = new CSSLoaderError(
|
|
230
230
|
'Syntax Error',
|
|
231
231
|
err.reason,
|
|
232
232
|
err.line != null && err.column != null
|
|
@@ -242,7 +242,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
function formatMessage (message, loc, source) {
|
|
245
|
-
|
|
245
|
+
let formatted = message
|
|
246
246
|
if (loc) {
|
|
247
247
|
formatted = formatted +
|
|
248
248
|
' (' + loc.line + ':' + loc.column + ')'
|
|
@@ -260,7 +260,7 @@ function CSSLoaderError (name, message, loc, source, error) {
|
|
|
260
260
|
this.name = name
|
|
261
261
|
this.error = error
|
|
262
262
|
this.message = formatMessage(message, loc, source)
|
|
263
|
-
this.
|
|
263
|
+
this.message = formatMessage(message, loc, source)
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
CSSLoaderError.prototype = Object.create(Error.prototype)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.0-beta.
|
|
3
|
+
"version": "2.7.0-beta.8",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"lib"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@babel/code-frame": "^7.16.0",
|
|
19
|
+
"@babel/generator": "^7.16.0",
|
|
20
|
+
"@babel/parser": "^7.16.2",
|
|
21
|
+
"@babel/traverse": "^7.16.0",
|
|
22
|
+
"@babel/types": "^7.16.0",
|
|
18
23
|
"@better-scroll/core": "^2.2.1",
|
|
19
24
|
"@better-scroll/movable": "^2.2.1",
|
|
20
25
|
"@better-scroll/observe-dom": "^2.2.1",
|
|
@@ -24,11 +29,6 @@
|
|
|
24
29
|
"@better-scroll/zoom": "^2.2.1",
|
|
25
30
|
"acorn-walk": "^7.2.0",
|
|
26
31
|
"async": "^2.6.0",
|
|
27
|
-
"babel-code-frame": "^6.26.0",
|
|
28
|
-
"babel-generator": "^6.26.1",
|
|
29
|
-
"babel-traverse": "^6.26.0",
|
|
30
|
-
"babel-types": "^6.26.0",
|
|
31
|
-
"babylon": "^6.18.0",
|
|
32
32
|
"consolidate": "^0.15.1",
|
|
33
33
|
"css": "^2.2.1",
|
|
34
34
|
"css-selector-tokenizer": "^0.7.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"html-minifier": "^3.5.8",
|
|
41
41
|
"icss-utils": "^2.1.0",
|
|
42
42
|
"json5": "^2.1.3",
|
|
43
|
-
"loader-utils": "
|
|
43
|
+
"loader-utils": "^2.0.2",
|
|
44
44
|
"lodash": "^4.17.15",
|
|
45
45
|
"lodash.camelcase": "^4.3.0",
|
|
46
46
|
"lru-cache": "^4.1.2",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"@types/babel-traverse": "^6.25.4",
|
|
78
78
|
"@types/babel-types": "^7.0.4"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "73247d266ae7380b88295208d645f85b9dd72398"
|
|
81
81
|
}
|
package/lib/built-in-loader.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const parseComponent = require('./parser')
|
|
2
|
-
const loaderUtils = require('loader-utils')
|
|
3
|
-
const parseRequest = require('./utils/parse-request')
|
|
4
|
-
const normalize = require('./utils/normalize')
|
|
5
|
-
const selectorPath = normalize.lib('selector')
|
|
6
|
-
const genComponentTag = require('./utils/gen-component-tag')
|
|
7
|
-
|
|
8
|
-
module.exports = function (content) {
|
|
9
|
-
this.cacheable()
|
|
10
|
-
const mpx = this.getMpx()
|
|
11
|
-
if (!mpx) {
|
|
12
|
-
return content
|
|
13
|
-
}
|
|
14
|
-
const mode = mpx.mode
|
|
15
|
-
const env = mpx.env
|
|
16
|
-
const resourcePath = parseRequest(this.resource).resourcePath
|
|
17
|
-
const parts = parseComponent(content, {
|
|
18
|
-
filePath: resourcePath,
|
|
19
|
-
needMap: this.sourceMap,
|
|
20
|
-
mode,
|
|
21
|
-
env
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
let output = ''
|
|
25
|
-
|
|
26
|
-
// 内建组件编写规范比较统一,不需要处理太多情况
|
|
27
|
-
if (parts.template) {
|
|
28
|
-
output += genComponentTag(parts.template)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (parts.script) {
|
|
32
|
-
output += '\n' + genComponentTag(parts.script, (script) => {
|
|
33
|
-
let content = ''
|
|
34
|
-
if (parts.styles && parts.styles.length) {
|
|
35
|
-
parts.styles.forEach((style, i) => {
|
|
36
|
-
const requestString = loaderUtils.stringifyRequest(this, `builtInComponent.styl!=!${selectorPath}?type=styles&index=${i}!${loaderUtils.getRemainingRequest(this)}`)
|
|
37
|
-
content += `\n import ${requestString}`
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
content += script.content
|
|
41
|
-
return content
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
return output
|
|
45
|
-
}
|
package/lib/record-loader.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const parseRequest = require('./utils/parse-request')
|
|
2
|
-
const RecordStaticResourceDependency = require('./dependencies/RecordStaticResourceDependency')
|
|
3
|
-
|
|
4
|
-
module.exports = function (source) {
|
|
5
|
-
const mpx = this.getMpx()
|
|
6
|
-
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
7
|
-
const file = mpx.getExtractedFile(this.resource)
|
|
8
|
-
const packageRoot = queryObj.packageRoot || ''
|
|
9
|
-
this._module.addPresentationalDependency(new RecordStaticResourceDependency(resourcePath, file, packageRoot))
|
|
10
|
-
return source
|
|
11
|
-
}
|