@mpxjs/webpack-plugin 2.8.39 → 2.8.40-test

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.
Files changed (51) hide show
  1. package/lib/dependencies/CommonJsExtractDependency.js +51 -0
  2. package/lib/dependencies/ResolveDependency.js +11 -9
  3. package/lib/extractor.js +1 -0
  4. package/lib/helpers.js +9 -1
  5. package/lib/index.js +173 -72
  6. package/lib/json-compiler/helper.js +25 -9
  7. package/lib/json-compiler/index.js +77 -28
  8. package/lib/loader.js +3 -10
  9. package/lib/native-loader.js +21 -14
  10. package/lib/platform/json/wx/index.js +65 -2
  11. package/lib/platform/run-rules.js +2 -1
  12. package/lib/platform/template/normalize-component-rules.js +2 -0
  13. package/lib/platform/template/wx/component-config/README.md +1 -1
  14. package/lib/platform/template/wx/component-config/fix-html-tag.js +17 -0
  15. package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
  16. package/lib/platform/template/wx/component-config/index.js +4 -2
  17. package/lib/platform/template/wx/component-config/view.js +0 -11
  18. package/lib/platform/template/wx/index.js +65 -18
  19. package/lib/runtime/base.styl +0 -5
  20. package/lib/runtime/components/web/filterTag.js +9 -30
  21. package/lib/runtime/components/web/getInnerListeners.js +2 -14
  22. package/lib/runtime/components/web/mpx-keep-alive.vue +10 -17
  23. package/lib/runtime/components/web/mpx-movable-view.vue +105 -23
  24. package/lib/runtime/components/web/mpx-picker-view.vue +1 -1
  25. package/lib/runtime/components/web/mpx-scroll-view.vue +69 -23
  26. package/lib/runtime/components/web/mpx-swiper.vue +152 -62
  27. package/lib/runtime/components/web/mpx-video.vue +123 -89
  28. package/lib/runtime/components/web/mpx-web-view.vue +120 -81
  29. package/lib/runtime/components/web/promisify.js +19 -0
  30. package/lib/runtime/components/wx/default-page.mpx +27 -0
  31. package/lib/runtime/optionProcessor.js +12 -18
  32. package/lib/style-compiler/index.js +5 -1
  33. package/lib/template-compiler/bind-this.js +280 -49
  34. package/lib/template-compiler/compiler.js +54 -58
  35. package/lib/template-compiler/index.js +35 -23
  36. package/lib/utils/dom-tag-config.js +115 -0
  37. package/lib/utils/make-map.js +12 -0
  38. package/lib/utils/string.js +7 -1
  39. package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -5
  40. package/lib/web/processJSON.js +35 -0
  41. package/lib/web/processScript.js +7 -4
  42. package/lib/web/processTemplate.js +7 -34
  43. package/package.json +4 -4
  44. package/lib/partial-compile/index.js +0 -35
  45. package/lib/template-compiler/preprocessor.js +0 -29
  46. package/lib/wxss/compile-exports.js +0 -52
  47. package/lib/wxss/createResolver.js +0 -36
  48. package/lib/wxss/css-base.js +0 -79
  49. package/lib/wxss/getLocalIdent.js +0 -25
  50. package/lib/wxss/localsLoader.js +0 -44
  51. package/lib/wxss/processCss.js +0 -274
@@ -0,0 +1,115 @@
1
+ // These tag configs are shared between compiler-dom and runtime-dom, so they
2
+ // must be extracted in shared to avoid creating a dependency between the two.
3
+ const makeMap = require('./make-map')
4
+
5
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
6
+ const HTML_TAGS =
7
+ 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
8
+ 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
9
+ 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
10
+ 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
11
+ 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
12
+ 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
13
+ 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
14
+ 'option,output,progress,select,textarea,details,dialog,menu,' +
15
+ 'summary,template,blockquote,iframe,tfoot'
16
+
17
+ // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
18
+ const SVG_TAGS =
19
+ 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
20
+ 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
21
+ 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
22
+ 'feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
23
+ 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
24
+ 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
25
+ 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
26
+ 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
27
+ 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
28
+ 'text,textPath,title,tspan,unknown,use,view'
29
+
30
+ const VOID_TAGS =
31
+ 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr'
32
+
33
+ // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
34
+ // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
35
+ const isNonPhrasingTag = makeMap(
36
+ 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
37
+ 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
38
+ 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
39
+ 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
40
+ 'title,tr,track'
41
+ )
42
+
43
+ const isRichTextTag = makeMap(
44
+ 'a,abbr,address,article,aside,b,bdi,bdo,big,blockquote,br,caption,' +
45
+ 'center,cite,code,col,colgroup,dd,del,div,dl,dt,em,fieldset,' +
46
+ 'font,footer,h1,h2,h3,h4,h5,h6,header,hr,i,img,ins,label,legend,' +
47
+ 'li,mark,nav,ol,p,pre,q,rt,ruby,s,section,small,span,strong,sub,sup,' +
48
+ 'table,tbody,td,tfoot,th,thead,tr,tt,u,ul'
49
+ )
50
+
51
+ const isUnaryTag = makeMap(
52
+ 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
53
+ 'link,meta,param,source,track,wbr'
54
+ )
55
+
56
+ // https://developers.weixin.qq.com/miniprogram/dev/component/
57
+ // 以后可能在框架中原生支持这些标签,所以需要进行判断
58
+ const isNativeMiniTag = makeMap(
59
+ 'cover-image,cover-view,match-media,movable-area,movable-view,' +
60
+ 'page-container,root-portal,scroll-view,swiper,swiper-item,view,' +
61
+ 'icon,progress,rich-text,text,button,checkbox,checkbox-group,editor,' +
62
+ 'form,input,keyboard-accessory,label,picker,picker-view,' +
63
+ 'picker-view-column,radio,radio-group,slider,switch,textarea,' +
64
+ 'grid-view,list-view,share-element,snapshot,span,sticky-header,' +
65
+ 'sticky-section,functional-page-navigator,navigator,audio,camera,' +
66
+ 'channel-live,channel-video,image,live-player,live-pusher,video,' +
67
+ 'voip-room,map,canvas,web-view,ad,ad-custom,official-account,' +
68
+ 'open-data,native-component,aria-component,page-meta'
69
+ )
70
+
71
+ /**
72
+ * 是否为mpx内置组件
73
+ * collected from packages/webpack-plugin/lib/runtime/components/web/
74
+ */
75
+ const isBuildInTag = makeMap(
76
+ 'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
77
+ 'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
78
+ 'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
79
+ 'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' +
80
+ 'mpx-tab-bar-container,mpx-form,mpx-navigator,mpx-rich-text,mpx-tab-bar,' +
81
+ 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
82
+ )
83
+
84
+ const isSpace = makeMap('ensp,emsp,nbsp')
85
+
86
+ const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
87
+
88
+ const isContHeight = makeMap('img,td,th,tr')
89
+
90
+ const isContConRow = makeMap('td,th,tr')
91
+
92
+ const isHTMLTag = makeMap(HTML_TAGS)
93
+
94
+ const isSVGTag = makeMap(SVG_TAGS)
95
+
96
+ const isVoidTag = makeMap(VOID_TAGS)
97
+
98
+ // 是否为原始tag,包括 html tag 和小程序原生 tag
99
+ const isOriginTag = (tag) => isHTMLTag(tag) || isSVGTag(tag) || isVoidTag(tag) || isNativeMiniTag(tag)
100
+
101
+ module.exports = {
102
+ isOriginTag,
103
+ isHTMLTag,
104
+ isSVGTag,
105
+ isVoidTag,
106
+ isNonPhrasingTag,
107
+ isRichTextTag,
108
+ isBuildInTag,
109
+ isUnaryTag,
110
+ isSpace,
111
+ isContWidth,
112
+ isContHeight,
113
+ isNativeMiniTag,
114
+ isContConRow
115
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Make a map and return a function for checking if a key
3
+ * is in that map.
4
+ */
5
+ module.exports = function makeMap (str, expectsLowerCase) {
6
+ const map = Object.create(null)
7
+ const list = str.split(',')
8
+ for (let i = 0; i < list.length; i++) {
9
+ map[list[i]] = true
10
+ }
11
+ return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
12
+ }
@@ -23,8 +23,14 @@ function capitalToHyphen (v) {
23
23
  return ret
24
24
  }
25
25
 
26
+ // 删除空行
27
+ function trimBlankRow (str) {
28
+ return str.replace(/^\s*[\r\n]/gm, '')
29
+ }
30
+
26
31
  module.exports = {
27
32
  isCapital,
28
33
  isMustache,
29
- capitalToHyphen
34
+ capitalToHyphen,
35
+ trimBlankRow
30
36
  }
@@ -1,10 +1,9 @@
1
1
  module.exports = (loaders, loaderIndex) => {
2
- for (let len = loaders.length; len > 0; --len) {
3
- const currentLoader = loaders[len - 1]
4
- if (currentLoader.path.endsWith('ts-loader/dist/stringify-loader.js')) {
5
- break
2
+ for (let i = loaderIndex; i >= 0; i--) {
3
+ const currentLoader = loaders[i]
4
+ if (currentLoader.path.endsWith('node_modules/ts-loader/dist/stringify-loader.js')) {
5
+ return i
6
6
  }
7
- loaderIndex--
8
7
  }
9
8
  return loaderIndex
10
9
  }
@@ -9,8 +9,10 @@ const parseComponent = require('../parser')
9
9
  const getJSONContent = require('../utils/get-json-content')
10
10
  const resolve = require('../utils/resolve')
11
11
  const createJSONHelper = require('../json-compiler/helper')
12
+ const getRulesRunner = require('../platform/index')
12
13
  const { RESOLVE_IGNORED_ERR } = require('../utils/const')
13
14
  const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
15
+ const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency')
14
16
 
15
17
  module.exports = function (json, {
16
18
  loaderContext,
@@ -26,6 +28,7 @@ module.exports = function (json, {
26
28
  const mpx = loaderContext.getMpx()
27
29
  const {
28
30
  mode,
31
+ srcMode,
29
32
  env,
30
33
  projectRoot
31
34
  } = mpx
@@ -75,12 +78,44 @@ module.exports = function (json, {
75
78
  })
76
79
  }
77
80
 
81
+ const { resourcePath } = parseRequest(loaderContext.resource)
82
+ const isApp = !(pagesMap[resourcePath] || componentsMap[resourcePath])
83
+
78
84
  if (!json) {
79
85
  return callback()
80
86
  }
81
87
  // 由于json需要提前读取在template处理中使用,src的场景已经在loader中处理了,此处无需考虑json.src的场景
82
88
  try {
83
89
  jsonObj = JSON5.parse(json.content)
90
+ // 处理runner
91
+ const rulesRunnerOptions = {
92
+ mode,
93
+ srcMode,
94
+ type: 'json',
95
+ waterfall: true,
96
+ warn: emitWarning,
97
+ error: emitError,
98
+ data: {
99
+ // polyfill global usingComponents & record globalComponents
100
+ globalComponents: mpx.usingComponents
101
+ }
102
+ }
103
+
104
+ if (!isApp) {
105
+ rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component'
106
+ }
107
+
108
+ const rulesRunner = getRulesRunner(rulesRunnerOptions)
109
+
110
+ if (rulesRunner) {
111
+ rulesRunner(jsonObj)
112
+ }
113
+ if (isApp) {
114
+ // 收集全局组件
115
+ Object.assign(mpx.usingComponents, jsonObj.usingComponents)
116
+ // 在 rulesRunner 运行后保存全局注册组件
117
+ loaderContext._module.addPresentationalDependency(new RecordGlobalComponentsDependency(mpx.usingComponents, loaderContext.context))
118
+ }
84
119
  } catch (e) {
85
120
  return callback(e)
86
121
  }
@@ -111,9 +111,10 @@ module.exports = function (script, {
111
111
  Vue.use(VueRouter)
112
112
  global.getApp = function(){}
113
113
  global.getCurrentPages = function(){
114
- if(!global.__mpxRouter) return []
114
+ const router = global.__mpxRouter
115
+ if(!router) return []
115
116
  // @ts-ignore
116
- return global.__mpxRouter.stack.map(item => {
117
+ return (router.lastStack || router.stack).map(item => {
117
118
  let page
118
119
  const vnode = item.vnode
119
120
  if(vnode && vnode.componentInstance) {
@@ -182,8 +183,10 @@ module.exports = function (script, {
182
183
  pagesMap[pagePath] = `getComponent(require(${pageRequest}), { __mpxPageRoute: ${JSON.stringify(pagePath)} })`
183
184
  }
184
185
  }
185
-
186
- if (pageCfg.isFirst) {
186
+ if (pagePath === jsonConfig.entryPagePath) {
187
+ firstPage = pagePath
188
+ }
189
+ if (!firstPage && pageCfg.isFirst) {
187
190
  firstPage = pagePath
188
191
  }
189
192
  })
@@ -2,23 +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
- // const { matchCondition } = require('../utils/match-condition')
6
-
7
- function calculateRootEleChild (arr) {
8
- if (!arr) {
9
- return 0
10
- }
11
- return arr.reduce((total, item) => {
12
- if (item.type === 1) {
13
- if (item.tag === 'template') {
14
- total += calculateRootEleChild(item.children)
15
- } else {
16
- total += 1
17
- }
18
- }
19
- return total
20
- }, 0)
21
- }
5
+ const { matchCondition } = require('../utils/match-condition')
22
6
 
23
7
  module.exports = function (template, {
24
8
  loaderContext,
@@ -38,8 +22,8 @@ module.exports = function (template, {
38
22
  wxsContentMap,
39
23
  decodeHTMLText,
40
24
  externalClasses,
41
- checkUsingComponents
42
- // autoVirtualHostRules
25
+ checkUsingComponents,
26
+ autoVirtualHostRules
43
27
  } = mpx
44
28
  const { resourcePath } = parseRequest(loaderContext.resource)
45
29
  const builtInComponentsMap = {}
@@ -72,6 +56,7 @@ module.exports = function (template, {
72
56
  }
73
57
  if (template.content) {
74
58
  const templateSrcMode = template.mode || srcMode
59
+
75
60
  const { root, meta } = templateCompiler.parse(template.content, {
76
61
  warn: (msg) => {
77
62
  loaderContext.emitWarning(
@@ -87,6 +72,7 @@ module.exports = function (template, {
87
72
  hasComment,
88
73
  isNative,
89
74
  isComponent: ctorType === 'component',
75
+ isPage: ctorType === 'page',
90
76
  mode,
91
77
  srcMode: templateSrcMode,
92
78
  defs,
@@ -101,9 +87,8 @@ module.exports = function (template, {
101
87
  // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
102
88
  globalComponents: [],
103
89
  // web模式下实现抽象组件
104
- componentGenerics
105
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
106
- // hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
90
+ componentGenerics,
91
+ hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
107
92
  })
108
93
  if (meta.wxsModuleMap) {
109
94
  wxsModuleMap = meta.wxsModuleMap
@@ -123,18 +108,6 @@ module.exports = function (template, {
123
108
  if (meta.genericsInfo) {
124
109
  genericsInfo = meta.genericsInfo
125
110
  }
126
- // 输出H5有多个root element时, 使用mpx-root-view标签包裹
127
- // todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
128
- if (root.tag === 'temp-node') {
129
- const childLen = calculateRootEleChild(root.children)
130
- if (childLen >= 2) {
131
- root.tag = 'div'
132
- templateCompiler.addAttrs(root, [{
133
- name: 'class',
134
- value: 'mpx-root-view'
135
- }])
136
- }
137
- }
138
111
  return templateCompiler.serialize(root)
139
112
  }
140
113
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.39",
3
+ "version": "2.8.40-test",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -29,7 +29,6 @@
29
29
  "@better-scroll/zoom": "^2.5.1",
30
30
  "acorn-walk": "^7.2.0",
31
31
  "async": "^2.6.0",
32
- "consolidate": "^0.15.1",
33
32
  "css": "^2.2.1",
34
33
  "css-selector-tokenizer": "^0.7.0",
35
34
  "cssnano": "^5.0.16",
@@ -55,7 +54,8 @@
55
54
  "postcss-modules-values": "^4.0.0",
56
55
  "postcss-selector-parser": "^6.0.8",
57
56
  "postcss-value-parser": "^4.0.2",
58
- "source-list-map": "^2.0.0"
57
+ "source-list-map": "^2.0.0",
58
+ "video.js": "^8.6.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "webpack": "^5.48.0"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "c11c93eeb5315c5ff54df7ace05709a21bdaea53"
85
+ "gitHead": "8524f9b69ebcfb0667ebff2608cf6f675f14f141"
86
86
  }
@@ -1,35 +0,0 @@
1
- const { matchCondition } = require('../utils/match-condition')
2
- const { parseQuery } = require('loader-utils')
3
-
4
- class MpxPartialCompilePlugin {
5
- constructor (condition) {
6
- this.condition = condition
7
- }
8
-
9
- isResolvingPage (obj) {
10
- // valid query should start with '?'
11
- const query = obj.query || '?'
12
- return parseQuery(query).isPage
13
- }
14
-
15
- apply (compiler) {
16
- compiler.resolverFactory.hooks.resolver.intercept({
17
- factory: (type, hook) => {
18
- hook.tap('MpxPartialCompilePlugin', (resolver) => {
19
- resolver.hooks.result.tapAsync({
20
- name: 'MpxPartialCompilePlugin',
21
- stage: -100
22
- }, (obj, resolverContext, callback) => {
23
- if (this.isResolvingPage(obj) && !matchCondition(obj.path, this.condition)) {
24
- obj.path = false
25
- }
26
- callback(null, obj)
27
- })
28
- })
29
- return hook
30
- }
31
- })
32
- }
33
- }
34
-
35
- module.exports = MpxPartialCompilePlugin
@@ -1,29 +0,0 @@
1
- // loader for pre-processing templates with e.g. pug
2
-
3
- const cons = require('consolidate')
4
- const loaderUtils = require('loader-utils')
5
-
6
- module.exports = function (content) {
7
- this.cacheable && this.cacheable()
8
- const callback = this.async()
9
- const opt = loaderUtils.getOptions(this) || {}
10
-
11
- if (!cons[opt.engine]) {
12
- return callback(new Error(
13
- 'Template engine \'' + opt.engine + '\' ' +
14
- 'isn\'t available in Consolidate.js'
15
- ))
16
- }
17
-
18
- const templateOption = opt.templateOption
19
-
20
- // for relative includes
21
- templateOption.filename = this.resourcePath
22
-
23
- cons[opt.engine].render(content, templateOption, function (err, html) {
24
- if (err) {
25
- return callback(err)
26
- }
27
- callback(null, html)
28
- })
29
- }
@@ -1,52 +0,0 @@
1
- const camelCase = require('lodash.camelcase')
2
-
3
- function dashesCamelCase (str) {
4
- return str.replace(/-+(\w)/g, function (match, firstLetter) {
5
- return firstLetter.toUpperCase()
6
- })
7
- }
8
-
9
- module.exports = function compileExports (result, importItemMatcher, camelCaseKeys) {
10
- if (!Object.keys(result.exports).length) {
11
- return ''
12
- }
13
-
14
- const exportJs = Object.keys(result.exports).reduce(function (res, key) {
15
- let valueAsString = JSON.stringify(result.exports[key])
16
- valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher)
17
-
18
- function addEntry (k) {
19
- res.push('\t' + JSON.stringify(k) + ': ' + valueAsString)
20
- }
21
-
22
- let targetKey
23
- switch (camelCaseKeys) {
24
- case true:
25
- addEntry(key)
26
- targetKey = camelCase(key)
27
- if (targetKey !== key) {
28
- addEntry(targetKey)
29
- }
30
- break
31
- case 'dashes':
32
- addEntry(key)
33
- targetKey = dashesCamelCase(key)
34
- if (targetKey !== key) {
35
- addEntry(targetKey)
36
- }
37
- break
38
- case 'only':
39
- addEntry(camelCase(key))
40
- break
41
- case 'dashesOnly':
42
- addEntry(dashesCamelCase(key))
43
- break
44
- default:
45
- addEntry(key)
46
- break
47
- }
48
- return res
49
- }, []).join(',\n')
50
-
51
- return '{\n' + exportJs + '\n}'
52
- }
@@ -1,36 +0,0 @@
1
- module.exports = function createResolver (alias) {
2
- if (typeof alias !== 'object' || Array.isArray(alias)) {
3
- return function (url) {
4
- return url
5
- }
6
- }
7
-
8
- alias = Object.keys(alias).map(function (key) {
9
- let onlyModule = false
10
- let obj = alias[key]
11
- if (/\$$/.test(key)) {
12
- onlyModule = true
13
- key = key.substr(0, key.length - 1)
14
- }
15
- if (typeof obj === 'string') {
16
- obj = {
17
- alias: obj
18
- }
19
- }
20
- obj = Object.assign({
21
- name: key,
22
- onlyModule: onlyModule
23
- }, obj)
24
- return obj
25
- })
26
-
27
- return function (url) {
28
- alias.forEach(function (obj) {
29
- const name = obj.name
30
- if (url === name || (!obj.onlyModule && url.startsWith(name + '/'))) {
31
- url = obj.alias + url.substr(name.length)
32
- }
33
- })
34
- return url
35
- }
36
- }
@@ -1,79 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- // css base code, injected by the css-loader
7
- module.exports = function (useSourceMap) {
8
- const list = []
9
-
10
- // return the list of modules as css string
11
- list.toString = function toString () {
12
- return this.map(function (item) {
13
- const content = cssWithMappingToString(item, useSourceMap)
14
- if (item[2]) {
15
- return '@media ' + item[2] + '{' + content + '}'
16
- } else {
17
- return content
18
- }
19
- }).join('')
20
- }
21
-
22
- // import a list of modules into the list
23
- list.i = function (modules, mediaQuery) {
24
- if (typeof modules === 'string') {
25
- modules = [[null, modules, '']]
26
- }
27
- const alreadyImportedModules = {}
28
- for (let i = 0; i < this.length; i++) {
29
- const id = this[i][0]
30
- if (typeof id === 'number') {
31
- alreadyImportedModules[id] = true
32
- }
33
- }
34
- for (let i = 0; i < modules.length; i++) {
35
- const item = modules[i]
36
- // skip already imported module
37
- // this implementation is not 100% perfect for weird media query combinations
38
- // when a module is imported multiple times with different media queries.
39
- // I hope this will never occur (Hey this way we have smaller bundles)
40
- if (typeof item[0] !== 'number' || !alreadyImportedModules[item[0]]) {
41
- if (mediaQuery && !item[2]) {
42
- item[2] = mediaQuery
43
- } else if (mediaQuery) {
44
- item[2] = '(' + item[2] + ') and (' + mediaQuery + ')'
45
- }
46
- list.push(item)
47
- }
48
- }
49
- }
50
- return list
51
- }
52
-
53
- function cssWithMappingToString (item, useSourceMap) {
54
- const content = item[1] || ''
55
- const cssMapping = item[3]
56
- if (!cssMapping) {
57
- return content
58
- }
59
-
60
- if (useSourceMap && typeof btoa === 'function') {
61
- const sourceMapping = toComment(cssMapping)
62
- const sourceURLs = cssMapping.sources.map(function (source) {
63
- return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
64
- })
65
-
66
- return [content].concat(sourceURLs).concat([sourceMapping]).join('\n')
67
- }
68
-
69
- return [content].join('\n')
70
- }
71
-
72
- // Adapted from convert-source-map (MIT)
73
- function toComment (sourceMap) {
74
- // eslint-disable-next-line no-undef
75
- const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))
76
- const data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64
77
-
78
- return '/*# ' + data + ' */'
79
- }
@@ -1,25 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- const loaderUtils = require('loader-utils')
7
- const path = require('path')
8
-
9
- module.exports = function getLocalIdent (loaderContext, localIdentName, localName, options) {
10
- if (!options.context) {
11
- if (loaderContext.rootContext) {
12
- options.context = loaderContext.rootContext
13
- } else if (loaderContext.options && typeof loaderContext.options.context === 'string') {
14
- options.context = loaderContext.options.context
15
- } else {
16
- options.context = loaderContext.context
17
- }
18
- }
19
- const request = path.relative(options.context, loaderContext.resourcePath)
20
- options.content = options.hashPrefix + request + '+' + localName
21
- localIdentName = localIdentName.replace(/\[local\]/gi, localName)
22
- const hash = loaderUtils.interpolateName(loaderContext, localIdentName, options)
23
- /* eslint-disable prefer-regex-literals */
24
- return hash.replace(new RegExp('[^a-zA-Z0-9\\-_\u00A0-\uFFFF]', 'g'), '-').replace(/^((-?[0-9])|--)/, '_$1')
25
- }
@@ -1,44 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- const loaderUtils = require('loader-utils')
7
- const processCss = require('./processCss')
8
- const compileExports = require('./compile-exports')
9
- const createResolver = require('./createResolver')
10
-
11
- module.exports = function (content) {
12
- if (this.cacheable) this.cacheable()
13
- const callback = this.async()
14
- const query = loaderUtils.getOptions(this) || {}
15
- const moduleMode = query.modules || query.module
16
- const camelCaseKeys = query.camelCase || query.camelcase
17
- const resolve = createResolver(query.alias)
18
-
19
- processCss(content, null, {
20
- mode: moduleMode ? 'local' : 'global',
21
- query: query,
22
- minimize: this.minimize,
23
- loaderContext: this,
24
- resolve: resolve
25
- }, function (err, result) {
26
- if (err) return callback(err)
27
-
28
- function importItemMatcher (item) {
29
- const match = result.importItemRegExp.exec(item)
30
- const idx = +match[1]
31
- const importItem = result.importItems[idx]
32
- const importUrl = importItem.url
33
- return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ')' +
34
- '[' + JSON.stringify(importItem.export) + '] + "'
35
- }
36
-
37
- let exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys)
38
- if (exportJs) {
39
- exportJs = 'module.exports = ' + exportJs + ';'
40
- }
41
-
42
- callback(null, exportJs)
43
- }.bind(this))
44
- }