@mpxjs/webpack-plugin 2.9.38 → 2.9.40

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.
@@ -0,0 +1,13 @@
1
+ const path = require('path')
2
+
3
+ module.exports = function (packageName) {
4
+ const baseName = 'mpx-custom-element'
5
+ const rawFile = baseName + (packageName === 'main' ? '-main' : '')
6
+ const filePath = path.resolve(__dirname, `${rawFile}.mpx`)
7
+ const request = `${filePath}?mpxCustomElement&isComponent&p=${packageName}`
8
+
9
+ return {
10
+ request,
11
+ outputPath: baseName + '-' + packageName
12
+ }
13
+ }
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <wxs module="xs" src="~@mpxjs/template-engine/dist/utils.wxs"/>
3
+ </template>
4
+
5
+ <script src="./custom-element-script.js"></script>
6
+
7
+ <style>
8
+
9
+ </style>
10
+
11
+ <script name="json">
12
+
13
+ const json = require('./custom-element-json')
14
+
15
+ module.exports = {
16
+ ...json
17
+ }
18
+ </script>
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <wxs module="xs" src="~@mpxjs/template-engine/dist/utils.wxs"/>
3
+ </template>
4
+
5
+ <script src="./custom-element-script.js"></script>
6
+
7
+ <style>
8
+
9
+ </style>
10
+
11
+ <script name="json">
12
+
13
+ const json = require('./custom-element-json')
14
+
15
+ module.exports = {
16
+ ...json
17
+ }
18
+ </script>
@@ -1,14 +1,16 @@
1
1
  const path = require('path')
2
2
  const postcss = require('postcss')
3
3
  const loadPostcssConfig = require('./load-postcss-config')
4
- const { MPX_ROOT_VIEW } = require('../utils/const')
4
+ const { MPX_ROOT_VIEW, MPX_DISABLE_EXTRACTOR_CACHE } = require('../utils/const')
5
5
  const rpx = require('./plugins/rpx')
6
6
  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 cssArrayList = require('./plugins/css-array-list')
10
11
  const { matchCondition } = require('../utils/match-condition')
11
12
  const parseRequest = require('../utils/parse-request')
13
+ const RecordRuntimeInfoDependency = require('../dependencies/RecordRuntimeInfoDependency')
12
14
 
13
15
  module.exports = function (css, map) {
14
16
  this.cacheable()
@@ -22,6 +24,9 @@ module.exports = function (css, map) {
22
24
  const isApp = resourcePath === appInfo.resourcePath
23
25
  const transRpxRulesRaw = mpx.transRpxRules
24
26
  const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
27
+ const runtimeCompile = queryObj.isDynamic
28
+ const index = queryObj.index || 0
29
+ const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
25
30
 
26
31
  const transRpxFn = mpx.webConfig.transRpxFn
27
32
  const testResolveRange = (include = () => true, exclude) => {
@@ -85,6 +90,11 @@ module.exports = function (css, map) {
85
90
 
86
91
  const finalPlugins = config.prePlugins.concat(plugins, config.plugins)
87
92
 
93
+ const cssList = []
94
+ if (runtimeCompile) {
95
+ finalPlugins.push(cssArrayList(cssList))
96
+ }
97
+
88
98
  return postcss(finalPlugins)
89
99
  .process(css, options)
90
100
  .then(result => {
@@ -128,6 +138,13 @@ module.exports = function (css, map) {
128
138
  }
129
139
  }
130
140
 
141
+ if (runtimeCompile) {
142
+ // 包含了运行时组件的 style 模块必须每次都创建(但并不是每次都需要build),用于收集组件节点信息,传递信息以禁用父级extractor的缓存
143
+ this.emitFile(MPX_DISABLE_EXTRACTOR_CACHE, '', undefined, { skipEmit: true })
144
+ this._module.addPresentationalDependency(new RecordRuntimeInfoDependency(packageName, resourcePath, { type: 'style', info: cssList, index }))
145
+ return cb(null, '')
146
+ }
147
+
131
148
  const map = result.map && result.map.toJSON()
132
149
  cb(null, result.css, map)
133
150
  return null // silence bluebird warning
@@ -0,0 +1,26 @@
1
+ module.exports = (cssList = []) => {
2
+ // Work with options here
3
+
4
+ return {
5
+ postcssPlugin: 'css-array-list',
6
+ /*
7
+ Root (root, postcss) {
8
+ // Transform CSS AST here
9
+ }
10
+ */
11
+
12
+ Rule (rule) {
13
+ // todo 特殊字符的处理,vtree 内部是否有做处理
14
+ const selector = rule.selector.trim().replace('\n', '')
15
+ let decls = ''
16
+ if (rule.nodes && rule.nodes.length) {
17
+ rule.nodes.forEach(item => {
18
+ decls += `${item.prop}: ${item.value}; `
19
+ })
20
+ }
21
+ cssList.push([selector, decls])
22
+ }
23
+ }
24
+ }
25
+
26
+ module.exports.postcss = true