@mpxjs/webpack-plugin 2.7.0-beta.1 → 2.7.0-beta.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/dependencies/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsVariableDependency.js +9 -5
- package/lib/dependencies/DynamicEntryDependency.js +8 -3
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +41 -0
- package/lib/dependencies/{RecordStaticResourceDependency.js → RecordResourceMapDependency.js} +12 -7
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +8 -7
- package/lib/extractor.js +7 -4
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +1 -0
- package/lib/index.js +218 -146
- package/lib/json-compiler/helper.js +21 -25
- package/lib/json-compiler/index.js +70 -54
- package/lib/json-compiler/plugin.js +21 -5
- package/lib/loader.js +59 -77
- package/lib/native-loader.js +28 -65
- package/lib/parser.js +1 -2
- 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/record-loader.js +2 -2
- package/lib/resolver/AddEnvPlugin.js +3 -2
- package/lib/resolver/AddModePlugin.js +3 -2
- 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/selector.js +23 -5
- package/lib/style-compiler/index.js +8 -10
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +109 -46
- package/lib/template-compiler/index.js +3 -6
- package/lib/template-compiler/trans-dynamic-class-expr.js +3 -3
- package/lib/utils/const.js +5 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-json-content.js +41 -0
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -142
- package/lib/web/processScript.js +30 -30
- package/lib/web/processTemplate.js +56 -40
- package/lib/wxs/i18n-loader.js +1 -3
- package/lib/wxs/loader.js +24 -27
- package/lib/wxs/pre-loader.js +7 -8
- package/lib/wxss/processCss.js +44 -44
- package/package.json +8 -8
- package/lib/built-in-loader.js +0 -49
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
|
@@ -1,9 +1,9 @@
|
|
|
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
8
|
function calculateRootEleChild (arr) {
|
|
9
9
|
if (!arr) {
|
|
@@ -21,19 +21,30 @@ function calculateRootEleChild (arr) {
|
|
|
21
21
|
}, 0)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
module.exports = function (template,
|
|
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) {
|
|
35
|
+
const mpx = loaderContext.getMpx()
|
|
36
|
+
const {
|
|
37
|
+
mode,
|
|
38
|
+
defs,
|
|
39
|
+
wxsContentMap,
|
|
40
|
+
decodeHTMLText,
|
|
41
|
+
externalClasses,
|
|
42
|
+
checkUsingComponents
|
|
43
|
+
// autoVirtualHostRules
|
|
44
|
+
} = mpx
|
|
45
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
32
46
|
const builtInComponentsMap = {}
|
|
33
|
-
|
|
34
|
-
const mainCompilation = getMainCompilation(compilation)
|
|
35
|
-
const mpx = mainCompilation.__mpx__
|
|
36
|
-
const wxsContentMap = mpx.wxsContentMap
|
|
47
|
+
|
|
37
48
|
let wxsModuleMap, genericsInfo
|
|
38
49
|
let output = '/* template */\n'
|
|
39
50
|
|
|
@@ -43,7 +54,7 @@ module.exports = function (template, options, callback) {
|
|
|
43
54
|
content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
|
|
44
55
|
}
|
|
45
56
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
46
|
-
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 })
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -62,7 +73,7 @@ module.exports = function (template, options, callback) {
|
|
|
62
73
|
}
|
|
63
74
|
if (template.content) {
|
|
64
75
|
const templateSrcMode = template.mode || srcMode
|
|
65
|
-
const
|
|
76
|
+
const { root, meta } = templateCompiler.parse(template.content, {
|
|
66
77
|
warn: (msg) => {
|
|
67
78
|
loaderContext.emitWarning(
|
|
68
79
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
@@ -73,54 +84,59 @@ module.exports = function (template, options, callback) {
|
|
|
73
84
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
74
85
|
)
|
|
75
86
|
},
|
|
76
|
-
usingComponents
|
|
77
|
-
hasComment
|
|
78
|
-
isNative
|
|
79
|
-
basename: path.basename(resourcePath),
|
|
87
|
+
usingComponents,
|
|
88
|
+
hasComment,
|
|
89
|
+
isNative,
|
|
80
90
|
isComponent: ctorType === 'component',
|
|
81
91
|
mode,
|
|
82
92
|
srcMode: templateSrcMode,
|
|
83
93
|
defs,
|
|
84
|
-
decodeHTMLText
|
|
85
|
-
externalClasses
|
|
94
|
+
decodeHTMLText,
|
|
95
|
+
externalClasses,
|
|
86
96
|
// todo 后续输出web也采用mpx的scoped处理
|
|
87
|
-
// hasScoped:options.hasScoped,
|
|
88
97
|
hasScoped: false,
|
|
89
98
|
moduleId,
|
|
90
99
|
filePath: loaderContext.resourcePath,
|
|
91
100
|
i18n: null,
|
|
92
|
-
checkUsingComponents
|
|
101
|
+
checkUsingComponents,
|
|
93
102
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
94
103
|
globalComponents: [],
|
|
95
104
|
// web模式下实现抽象组件
|
|
96
|
-
componentGenerics
|
|
105
|
+
componentGenerics
|
|
106
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
107
|
+
// hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
97
108
|
})
|
|
98
|
-
if (
|
|
99
|
-
wxsModuleMap =
|
|
109
|
+
if (meta.wxsModuleMap) {
|
|
110
|
+
wxsModuleMap = meta.wxsModuleMap
|
|
100
111
|
}
|
|
101
|
-
if (
|
|
102
|
-
for (let module in
|
|
103
|
-
wxsContentMap[`${resourcePath}~${module}`] =
|
|
112
|
+
if (meta.wxsContentMap) {
|
|
113
|
+
for (let module in meta.wxsContentMap) {
|
|
114
|
+
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
104
115
|
}
|
|
105
116
|
}
|
|
106
|
-
if (
|
|
107
|
-
Object.keys(
|
|
117
|
+
if (meta.builtInComponentsMap) {
|
|
118
|
+
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
108
119
|
builtInComponentsMap[name] = {
|
|
109
|
-
resource: addQuery(
|
|
120
|
+
resource: addQuery(meta.builtInComponentsMap[name], { isComponent: true })
|
|
110
121
|
}
|
|
111
122
|
})
|
|
112
123
|
}
|
|
113
|
-
if (
|
|
114
|
-
genericsInfo =
|
|
124
|
+
if (meta.genericsInfo) {
|
|
125
|
+
genericsInfo = meta.genericsInfo
|
|
115
126
|
}
|
|
116
|
-
// 输出H5有多个root element时, 使用
|
|
117
|
-
|
|
118
|
-
|
|
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)
|
|
119
131
|
if (childLen >= 2) {
|
|
120
|
-
|
|
132
|
+
root.tag = 'div'
|
|
133
|
+
templateCompiler.addAttrs(root, [{
|
|
134
|
+
name: 'class',
|
|
135
|
+
value: 'mpx-root-view'
|
|
136
|
+
}])
|
|
121
137
|
}
|
|
122
138
|
}
|
|
123
|
-
return templateCompiler.serialize(
|
|
139
|
+
return templateCompiler.serialize(root)
|
|
124
140
|
}
|
|
125
141
|
})
|
|
126
142
|
output += '\n\n'
|
package/lib/wxs/i18n-loader.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// 该loader用于将用户定义的messages注入到i18n.wxs中
|
|
2
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
3
2
|
const loaderUtils = require('loader-utils')
|
|
4
3
|
|
|
5
4
|
module.exports = function (content) {
|
|
6
|
-
const
|
|
7
|
-
const i18n = mainCompilation.__mpx__.i18n
|
|
5
|
+
const i18n = this.getMpx().i18n
|
|
8
6
|
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__\n'
|
|
9
7
|
if (i18n) {
|
|
10
8
|
if (i18n.messages) {
|
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,22 +1,21 @@
|
|
|
1
|
-
const babylon = require('
|
|
2
|
-
const traverse = require('babel
|
|
3
|
-
const t = require('babel
|
|
4
|
-
const generate = require('babel
|
|
5
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
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
|
|
6
5
|
const parseRequest = require('../utils/parse-request')
|
|
7
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
7
|
const parseQuery = require('loader-utils').parseQuery
|
|
9
8
|
|
|
10
9
|
module.exports = function (content) {
|
|
11
10
|
this.cacheable()
|
|
12
|
-
const
|
|
11
|
+
const mpx = this.getMpx()
|
|
13
12
|
const module = this._module
|
|
14
|
-
const mode =
|
|
13
|
+
const mode = mpx.mode
|
|
15
14
|
const wxsModule = parseQuery(this.resourceQuery || '?').wxsModule
|
|
16
15
|
|
|
17
16
|
// 处理内联wxs
|
|
18
17
|
if (wxsModule) {
|
|
19
|
-
const wxsContentMap =
|
|
18
|
+
const wxsContentMap = mpx.wxsContentMap
|
|
20
19
|
const resourcePath = parseRequest(this.resource).resourcePath
|
|
21
20
|
content = wxsContentMap[`${resourcePath}~${wxsModule}`] || content
|
|
22
21
|
}
|
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.13",
|
|
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": "1f73f63dd36b91d20e2234ac2a36edce3e75a352"
|
|
81
81
|
}
|
package/lib/built-in-loader.js
DELETED
|
@@ -1,49 +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
|
-
const getMainCompilation = require('./utils/get-main-compilation')
|
|
8
|
-
|
|
9
|
-
module.exports = function (content) {
|
|
10
|
-
this.cacheable()
|
|
11
|
-
const mainCompilation = getMainCompilation(this._compilation)
|
|
12
|
-
const mpx = mainCompilation.__mpx__
|
|
13
|
-
if (!mpx) {
|
|
14
|
-
return content
|
|
15
|
-
}
|
|
16
|
-
const mode = mpx.mode
|
|
17
|
-
const env = mpx.env
|
|
18
|
-
const defs = mpx.defs
|
|
19
|
-
const resourcePath = parseRequest(this.resource).resourcePath
|
|
20
|
-
const parts = parseComponent(content, {
|
|
21
|
-
filePath: resourcePath,
|
|
22
|
-
needMap: this.sourceMap,
|
|
23
|
-
mode,
|
|
24
|
-
defs,
|
|
25
|
-
env
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
let output = ''
|
|
29
|
-
|
|
30
|
-
// 内建组件编写规范比较统一,不需要处理太多情况
|
|
31
|
-
if (parts.template) {
|
|
32
|
-
output += genComponentTag(parts.template)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (parts.script) {
|
|
36
|
-
output += '\n' + genComponentTag(parts.script, (script) => {
|
|
37
|
-
let content = ''
|
|
38
|
-
if (parts.styles && parts.styles.length) {
|
|
39
|
-
parts.styles.forEach((style, i) => {
|
|
40
|
-
const requestString = loaderUtils.stringifyRequest(this, `builtInComponent.styl!=!${selectorPath}?type=styles&index=${i}!${loaderUtils.getRemainingRequest(this)}`)
|
|
41
|
-
content += `\n import ${requestString}`
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
content += script.content
|
|
45
|
-
return content
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
return output
|
|
49
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const parseRequest = require('./parse-request')
|
|
2
|
-
const mpxJSON = require('./mpx-json')
|
|
3
|
-
const getMainCompilation = require('./get-main-compilation')
|
|
4
|
-
|
|
5
|
-
module.exports = function readJsonForSrc (src, loaderContext, callback) {
|
|
6
|
-
const fs = loaderContext._compiler.inputFileSystem
|
|
7
|
-
const mpx = getMainCompilation(loaderContext._compilation).__mpx__
|
|
8
|
-
const defs = mpx.defs
|
|
9
|
-
const resolve = (context, request, callback) => {
|
|
10
|
-
const { queryObj } = parseRequest(request)
|
|
11
|
-
context = queryObj.context || context
|
|
12
|
-
return loaderContext.resolve(context, request, callback)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
resolve(loaderContext.context, src, (err, result) => {
|
|
16
|
-
if (err) return callback(err)
|
|
17
|
-
const { rawResourcePath: resourcePath } = parseRequest(result)
|
|
18
|
-
loaderContext.addDependency(resourcePath)
|
|
19
|
-
fs.readFile(resourcePath, (err, content) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
return callback(err)
|
|
22
|
-
}
|
|
23
|
-
content = content.toString('utf-8')
|
|
24
|
-
if (resourcePath.endsWith('.json.js')) {
|
|
25
|
-
try {
|
|
26
|
-
content = mpxJSON.compileMPXJSONText({ source: content, defs, filePath: resourcePath })
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return callback(e)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
callback(null, content)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
}
|