@mpxjs/webpack-plugin 2.7.52 → 2.8.0-beta.2

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 (71) hide show
  1. package/lib/config.js +24 -24
  2. package/lib/dependencies/CommonJsVariableDependency.js +1 -1
  3. package/lib/dependencies/DynamicEntryDependency.js +18 -11
  4. package/lib/extractor.js +1 -1
  5. package/lib/helpers.js +3 -1
  6. package/lib/index.js +24 -21
  7. package/lib/json-compiler/helper.js +1 -1
  8. package/lib/json-compiler/index.js +17 -17
  9. package/lib/json-compiler/plugin.js +3 -2
  10. package/lib/json-compiler/theme.js +1 -1
  11. package/lib/loader.js +3 -3
  12. package/lib/native-loader.js +1 -1
  13. package/lib/platform/json/normalize-test.js +3 -1
  14. package/lib/platform/run-rules.js +2 -2
  15. package/lib/platform/template/wx/component-config/camera.js +3 -3
  16. package/lib/platform/template/wx/component-config/canvas.js +5 -5
  17. package/lib/platform/template/wx/component-config/map.js +5 -5
  18. package/lib/platform/template/wx/component-config/navigator.js +7 -7
  19. package/lib/platform/template/wx/component-config/progress.js +4 -4
  20. package/lib/platform/template/wx/component-config/scroll-view.js +3 -3
  21. package/lib/platform/template/wx/component-config/slider.js +6 -6
  22. package/lib/platform/template/wx/component-config/swiper.js +2 -2
  23. package/lib/platform/template/wx/component-config/video.js +4 -4
  24. package/lib/platform/template/wx/component-config/view.js +4 -4
  25. package/lib/platform/template/wx/index.js +45 -13
  26. package/lib/resolver/PackageEntryPlugin.js +1 -1
  27. package/lib/runtime/components/web/filterTag.js +6 -6
  28. package/lib/runtime/components/web/getInnerListeners.js +1 -1
  29. package/lib/runtime/components/web/mpx-button.vue +0 -1
  30. package/lib/runtime/components/web/mpx-icon.vue +1 -1
  31. package/lib/runtime/components/web/mpx-keep-alive.vue +2 -2
  32. package/lib/runtime/components/web/mpx-picker.vue +1 -1
  33. package/lib/runtime/components/web/mpx-progress.vue +1 -1
  34. package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
  35. package/lib/runtime/env.js +1 -0
  36. package/lib/runtime/i18n.wxs +44 -81
  37. package/lib/runtime/optionProcessor.d.ts +0 -4
  38. package/lib/runtime/optionProcessor.js +15 -13
  39. package/lib/runtime/stringify.wxs +3 -3
  40. package/lib/runtime/swanHelper.wxs +2 -2
  41. package/lib/runtime/{components/web/util.js → utils.js} +8 -5
  42. package/lib/script-setup-compiler/index.js +1163 -0
  43. package/lib/style-compiler/index.js +1 -1
  44. package/lib/style-compiler/plugins/rpx.js +1 -1
  45. package/lib/style-compiler/plugins/vw.js +6 -4
  46. package/lib/template-compiler/bind-this.js +5 -5
  47. package/lib/template-compiler/compiler.js +122 -179
  48. package/lib/template-compiler/index.js +3 -3
  49. package/lib/utils/add-query.js +2 -1
  50. package/lib/utils/gen-component-tag.js +1 -1
  51. package/lib/utils/has-own.js +5 -0
  52. package/lib/utils/is-empty-object.js +2 -1
  53. package/lib/utils/parse-request.js +3 -3
  54. package/lib/utils/{index.js → process-defs.js} +3 -10
  55. package/lib/utils/stringify-query.js +23 -21
  56. package/lib/web/processJSON.js +5 -5
  57. package/lib/web/processScript.js +16 -19
  58. package/lib/web/processTemplate.js +1 -1
  59. package/lib/wxml/loader.js +3 -3
  60. package/lib/wxs/i18n-loader.js +4 -11
  61. package/lib/wxs/pre-loader.js +51 -44
  62. package/lib/wxss/compile-exports.js +4 -4
  63. package/lib/wxss/createResolver.js +3 -3
  64. package/lib/wxss/css-base.js +13 -13
  65. package/lib/wxss/getLocalIdent.js +5 -4
  66. package/lib/wxss/loader.js +1 -1
  67. package/lib/wxss/localsLoader.js +14 -14
  68. package/lib/wxss/processCss.js +10 -7
  69. package/package.json +4 -3
  70. package/lib/utils/env.js +0 -4
  71. package/lib/utils/parse-asset.js +0 -195
@@ -63,19 +63,19 @@ module.exports = function (raw) {
63
63
  })
64
64
 
65
65
  if (meta.wxsContentMap) {
66
- for (let module in meta.wxsContentMap) {
66
+ for (const module in meta.wxsContentMap) {
67
67
  wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
68
68
  }
69
69
  }
70
70
 
71
71
  let resultSource = ''
72
72
 
73
- for (let module in meta.wxsModuleMap) {
73
+ for (const module in meta.wxsModuleMap) {
74
74
  const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], root)
75
75
  resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
76
76
  }
77
77
 
78
- let result = compiler.serialize(ast)
78
+ const result = compiler.serialize(ast)
79
79
 
80
80
  if (isNative) {
81
81
  return result
@@ -1,6 +1,7 @@
1
1
  const parseRequest = require('./parse-request')
2
2
  const stringifyQuery = require('./stringify-query')
3
3
  const type = require('./type')
4
+ const hasOwn = require('./has-own')
4
5
 
5
6
  // 默认为非强行覆盖原query,如需强行覆盖传递force为true
6
7
  module.exports = function addQuery (request, data = {}, force, removeKeys) {
@@ -10,7 +11,7 @@ module.exports = function addQuery (request, data = {}, force, removeKeys) {
10
11
  Object.assign(queryObj, data)
11
12
  } else {
12
13
  Object.keys(data).forEach((key) => {
13
- if (!queryObj.hasOwnProperty(key)) {
14
+ if (!hasOwn(queryObj, key)) {
14
15
  queryObj[key] = data[key]
15
16
  }
16
17
  })
@@ -5,7 +5,7 @@ function stringifyAttrs (attrs) {
5
5
  let result = ''
6
6
  Object.keys(attrs).forEach(function (name) {
7
7
  result += ' ' + name
8
- let value = attrs[name]
8
+ const value = attrs[name]
9
9
  if (value != null && value !== true) {
10
10
  result += '=' + stringifyAttr(value)
11
11
  }
@@ -0,0 +1,5 @@
1
+ const hasOwnProperty = Object.prototype.hasOwnProperty
2
+
3
+ module.exports = function hasOwn (obj, key) {
4
+ return hasOwnProperty.call(obj, key)
5
+ }
@@ -2,7 +2,8 @@ module.exports = function isEmptyObject (obj) {
2
2
  if (!obj) {
3
3
  return true
4
4
  }
5
- for (let key in obj) {
5
+ /* eslint-disable no-unreachable-loop */
6
+ for (const key in obj) {
6
7
  return false
7
8
  }
8
9
  return true
@@ -12,9 +12,9 @@ module.exports = function parseRequest (request) {
12
12
  if (seen.has(request)) {
13
13
  return genQueryObj(seen.get(request))
14
14
  }
15
- let elements = request.split('!')
16
- let resource = elements.pop()
17
- let loaderString = elements.join('!')
15
+ const elements = request.split('!')
16
+ const resource = elements.pop()
17
+ const loaderString = elements.join('!')
18
18
  let resourcePath = resource
19
19
  let resourceQuery = ''
20
20
  const queryIndex = resource.indexOf('?')
@@ -1,15 +1,12 @@
1
- /**
2
- * @file common util methods
3
- */
4
-
5
1
  /**
6
2
  * 预处理一次常量对象,处理掉不符合标识符规则的变量,目前只处理'.',用于在JSON/style中使用的场景
7
3
  * @param {object} defs 待处理的常量
8
4
  * @returns {object} 处理完毕的常量对象
9
5
  */
10
- function preProcessDefs (defs) {
6
+
7
+ module.exports = function processDefs (defs) {
11
8
  const newDefs = {}
12
- Object.keys(defs).map(key => {
9
+ Object.keys(defs).forEach(key => {
13
10
  if (typeof key === 'string' && key.indexOf('.') !== -1) {
14
11
  key.split('.').reduce((prev, curr, index, arr) => {
15
12
  if (index === arr.length - 1) {
@@ -25,7 +22,3 @@ function preProcessDefs (defs) {
25
22
  })
26
23
  return newDefs
27
24
  }
28
-
29
- module.exports = {
30
- preProcessDefs
31
- }
@@ -9,31 +9,33 @@ const JSON5 = require('json5')
9
9
  function stringifyQuery (obj, useJSON) {
10
10
  if (useJSON) return `?${JSON5.stringify(obj)}`
11
11
 
12
- const res = obj ? Object.keys(obj).sort().map(key => {
13
- const val = obj[key]
12
+ const res = obj
13
+ ? Object.keys(obj).sort().map(key => {
14
+ const val = obj[key]
14
15
 
15
- if (val === undefined) {
16
- return
17
- }
16
+ if (val === undefined) {
17
+ return val
18
+ }
18
19
 
19
- if (val === true) {
20
- return key
21
- }
20
+ if (val === true) {
21
+ return key
22
+ }
22
23
 
23
- if (Array.isArray(val)) {
24
- const key2 = `${key}[]`
25
- const result = []
26
- val.slice().forEach(val2 => {
27
- if (val2 === undefined) {
28
- return
29
- }
30
- result.push(`${key2}=${encodeURIComponent(val2)}`)
31
- })
32
- return result.join('&')
33
- }
24
+ if (Array.isArray(val)) {
25
+ const key2 = `${key}[]`
26
+ const result = []
27
+ val.slice().forEach(val2 => {
28
+ if (val2 === undefined) {
29
+ return
30
+ }
31
+ result.push(`${key2}=${encodeURIComponent(val2)}`)
32
+ })
33
+ return result.join('&')
34
+ }
34
35
 
35
- return `${key}=${encodeURIComponent(val)}`
36
- }).filter(x => x).join('&') : null
36
+ return `${key}=${encodeURIComponent(val)}`
37
+ }).filter(x => x).join('&')
38
+ : null
37
39
  return res ? `?${res}` : ''
38
40
  }
39
41
 
@@ -19,7 +19,7 @@ module.exports = function (json, {
19
19
  }, rawCallback) {
20
20
  const localPagesMap = {}
21
21
  const localComponentsMap = {}
22
- let output = '/* json */\n'
22
+ const output = '/* json */\n'
23
23
  let jsonObj = {}
24
24
  let tabBarMap
25
25
  let tabBarStr
@@ -157,10 +157,10 @@ module.exports = function (json, {
157
157
  const context = path.dirname(result)
158
158
 
159
159
  if (content.pages) {
160
- let tarRoot = queryObj.root
160
+ const tarRoot = queryObj.root
161
161
  if (tarRoot) {
162
162
  delete queryObj.root
163
- let subPackage = {
163
+ const subPackage = {
164
164
  tarRoot,
165
165
  pages: content.pages,
166
166
  ...queryObj
@@ -239,8 +239,8 @@ module.exports = function (json, {
239
239
  emitError(`Current subpackage root [${subPackage.root}] is not allow starts with '.'`)
240
240
  return callback()
241
241
  }
242
- let tarRoot = subPackage.tarRoot || subPackage.root || ''
243
- let srcRoot = subPackage.srcRoot || subPackage.root || ''
242
+ const tarRoot = subPackage.tarRoot || subPackage.root || ''
243
+ const srcRoot = subPackage.srcRoot || subPackage.root || ''
244
244
  if (!tarRoot) return callback()
245
245
  context = path.join(context, srcRoot)
246
246
  processPages(subPackage.pages, context, tarRoot, callback)
@@ -2,15 +2,16 @@ 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 hasOwn = require('../utils/has-own')
5
6
  const createHelpers = require('../helpers')
6
7
  const optionProcessorPath = normalize.lib('runtime/optionProcessor')
7
8
  const tabBarContainerPath = normalize.lib('runtime/components/web/mpx-tab-bar-container.vue')
8
9
  const tabBarPath = normalize.lib('runtime/components/web/mpx-tab-bar.vue')
9
10
 
10
11
  function shallowStringify (obj) {
11
- let arr = []
12
- for (let key in obj) {
13
- if (obj.hasOwnProperty(key)) {
12
+ const arr = []
13
+ for (const key in obj) {
14
+ if (hasOwn(obj, key)) {
14
15
  let value = obj[key]
15
16
  if (Array.isArray(value)) {
16
17
  value = `[${value.join(',')}]`
@@ -61,7 +62,7 @@ module.exports = function (script, {
61
62
  }
62
63
 
63
64
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
64
- let tabBarPagesMap = {}
65
+ const tabBarPagesMap = {}
65
66
  if (tabBar && tabBarMap) {
66
67
  // 挂载tabBar组件
67
68
  const tabBarRequest = stringifyRequest(addQuery(tabBar.custom ? './custom-tab-bar/index' : tabBarPath, { isComponent: true }))
@@ -95,8 +96,8 @@ module.exports = function (script, {
95
96
  const attrs = Object.assign({}, script.attrs)
96
97
  // src改为内联require,删除
97
98
  delete attrs.src
98
- // 目前ts模式都建议使用src来引ts,不支持使用lang内联编写ts
99
- // delete attrs.lang
99
+ // script setup通过mpx处理,删除该属性避免vue报错
100
+ delete attrs.setup
100
101
  return attrs
101
102
  },
102
103
  content (script) {
@@ -130,7 +131,9 @@ module.exports = function (script, {
130
131
  if (i18n) {
131
132
  const i18nObj = Object.assign({}, i18n)
132
133
  content += ` import VueI18n from 'vue-i18n'
133
- Vue.use(VueI18n)\n`
134
+ import { createI18n } from 'vue-i18n-bridge'
135
+
136
+ Vue.use(VueI18n , { bridge: true })\n`
134
137
  const requestObj = {}
135
138
  const i18nKeys = ['messages', 'dateTimeFormats', 'numberFormats']
136
139
  i18nKeys.forEach((key) => {
@@ -143,12 +146,9 @@ module.exports = function (script, {
143
146
  Object.keys(requestObj).forEach((key) => {
144
147
  content += ` i18nCfg.${key} = require(${requestObj[key]})\n`
145
148
  })
146
- content += ` const i18n = new VueI18n(i18nCfg)
147
- i18n.mergeMessages = (newMessages) => {
148
- Object.keys(newMessages).forEach((locale) => {
149
- i18n.mergeLocaleMessage(locale, newMessages[locale])
150
- })
151
- }
149
+ content += ' i18nCfg.legacy = false\n'
150
+ content += ` const i18n = createI18n(i18nCfg, VueI18n)
151
+ Vue.use(i18n)
152
152
  Mpx.i18n = i18n
153
153
  \n`
154
154
  }
@@ -210,7 +210,8 @@ module.exports = function (script, {
210
210
 
211
211
  // 传递ctorType以补全js内容
212
212
  const extraOptions = {
213
- ctorType
213
+ ctorType,
214
+ lang: script.lang || 'js'
214
215
  }
215
216
  // todo 仅靠vueContentCache保障模块唯一性还是不够严谨,后续需要考虑去除原始query后构建request
216
217
  content += ` ${getRequire('script', script, extraOptions)}\n`
@@ -259,12 +260,8 @@ module.exports = function (script, {
259
260
  content += `,
260
261
  Vue,
261
262
  VueRouter`
262
- if (i18n) {
263
- content += `,
264
- i18n`
265
- }
266
263
  }
267
- content += `\n )\n`
264
+ content += '\n )\n'
268
265
  return content
269
266
  }
270
267
  })
@@ -109,7 +109,7 @@ module.exports = function (template, {
109
109
  wxsModuleMap = meta.wxsModuleMap
110
110
  }
111
111
  if (meta.wxsContentMap) {
112
- for (let module in meta.wxsContentMap) {
112
+ for (const module in meta.wxsContentMap) {
113
113
  wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
114
114
  }
115
115
  }
@@ -48,7 +48,7 @@ module.exports = function (content) {
48
48
  if (link.value.indexOf('mailto:') > -1) return
49
49
 
50
50
  // eslint-disable-next-line node/no-deprecated-api
51
- let uri = url.parse(link.value)
51
+ const uri = url.parse(link.value)
52
52
  if (uri.hash !== null && uri.hash !== undefined) {
53
53
  uri.hash = null
54
54
  link.value = uri.format()
@@ -60,7 +60,7 @@ module.exports = function (content) {
60
60
  ident = randomIdent()
61
61
  } while (data[ident])
62
62
  data[ident] = link
63
- let x = content.pop()
63
+ const x = content.pop()
64
64
  content.push(x.substr(link.start + link.length))
65
65
  content.push(ident)
66
66
  content.push(x.substr(0, link.start))
@@ -76,7 +76,7 @@ module.exports = function (content) {
76
76
 
77
77
  const link = data[match]
78
78
 
79
- let src = loaderUtils.urlToRequest(link.value, root)
79
+ const src = loaderUtils.urlToRequest(link.value, root)
80
80
 
81
81
  let requestString, extraOptions
82
82
 
@@ -3,26 +3,19 @@ const loaderUtils = require('loader-utils')
3
3
 
4
4
  module.exports = function (content) {
5
5
  const i18n = this.getMpx().i18n
6
- let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__, __mpx_locale__\n'
6
+ let prefix = 'var __mpx_messages__, __mpx_locale__, __mpx_fallback_locale__\n'
7
7
  if (i18n) {
8
8
  if (i18n.messages) {
9
9
  prefix += `__mpx_messages__ = ${JSON.stringify(i18n.messages)}\n`
10
10
  } else if (i18n.messagesPath) {
11
11
  prefix += `__mpx_messages__ = require(${loaderUtils.stringifyRequest(this, i18n.messagesPath)})\n`
12
12
  }
13
- if (i18n.dateTimeFormats) {
14
- prefix += `__mpx_datetime_formats__ = ${JSON.stringify(i18n.dateTimeFormats)}\n`
15
- } else if (i18n.dateTimeFormatsPath) {
16
- prefix += `__mpx_datetime_formats__ = require(${loaderUtils.stringifyRequest(this, i18n.dateTimeFormatsPath)})\n`
17
- }
18
- if (i18n.numberFormats) {
19
- prefix += `__mpx_number_formats__ = ${JSON.stringify(i18n.numberFormats)}\n`
20
- } else if (i18n.numberFormatsPath) {
21
- prefix += `__mpx_number_formats__ = require(${loaderUtils.stringifyRequest(this, i18n.numberFormatsPath)})\n`
22
- }
23
13
  if (i18n.locale) {
24
14
  prefix += `__mpx_locale__ = ${JSON.stringify(i18n.locale)}\n`
25
15
  }
16
+ if (i18n.fallbackLocale) {
17
+ prefix += `__mpx_fallback_locale__ = ${JSON.stringify(i18n.fallbackLocale)}\n`
18
+ }
26
19
  }
27
20
  content = prefix + content
28
21
  return content
@@ -22,54 +22,61 @@ module.exports = function (content) {
22
22
 
23
23
  const visitor = {}
24
24
 
25
- if (module.wxs && mode === 'ali') {
26
- let insertNodes = babylon.parse(
27
- 'var __mpx_args__ = [];\n' +
28
- 'for (var i = 0; i < arguments.length; i++) {\n' +
29
- ' __mpx_args__[i] = arguments[i];\n' +
30
- '}'
31
- ).program.body
32
- // todo Object.assign可能会覆盖,未来存在非预期的覆盖case时需要改进处理
33
- Object.assign(visitor, {
34
- Identifier (path) {
35
- if (path.node.name === 'arguments') {
36
- path.node.name = '__mpx_args__'
37
- const targetPath = path.getFunctionParent().get('body')
38
- if (!targetPath.inserted) {
39
- let results = targetPath.unshiftContainer('body', insertNodes) || []
40
- targetPath.inserted = true
41
- results.forEach((item) => {
42
- item.shouldStopTraverse = true
43
- })
25
+ if (module.wxs) {
26
+ if (mode === 'ali') {
27
+ const insertNodes = babylon.parse(
28
+ 'var __mpx_args__ = [];\n' +
29
+ 'for (var i = 0; i < arguments.length; i++) {\n' +
30
+ ' __mpx_args__[i] = arguments[i];\n' +
31
+ '}'
32
+ ).program.body
33
+ // todo Object.assign可能会覆盖,未来存在非预期的覆盖case时需要改进处理
34
+ Object.assign(visitor, {
35
+ Identifier (path) {
36
+ if (path.node.name === 'arguments') {
37
+ path.node.name = '__mpx_args__'
38
+ const targetPath = path.getFunctionParent().get('body')
39
+ if (!targetPath.inserted) {
40
+ const results = targetPath.unshiftContainer('body', insertNodes) || []
41
+ targetPath.inserted = true
42
+ results.forEach((item) => {
43
+ item.shouldStopTraverse = true
44
+ })
45
+ }
44
46
  }
45
- }
46
- },
47
- CallExpression (path) {
48
- const callee = path.node.callee
49
- if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
50
- const argPath = path.get('arguments')[0]
51
- if (argPath.isStringLiteral()) {
52
- argPath.replaceWith(t.stringLiteral(argPath.node.extra.raw.slice(1, -1)))
47
+ },
48
+ ForStatement (path) {
49
+ if (path.shouldStopTraverse) {
50
+ path.stop()
51
+ }
52
+ },
53
+ // 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
54
+ ExportNamedDeclaration (path) {
55
+ if (
56
+ path.node.declaration &&
57
+ path.node.declaration.declarations.length === 1 &&
58
+ path.node.declaration.declarations[0].id.name === path.node.declaration.declarations[0].init.name
59
+ ) {
60
+ const name = path.node.declaration.declarations[0].id.name
61
+ path.replaceWith(t.exportNamedDeclaration(undefined, [t.exportSpecifier(t.identifier(name), t.identifier(name))]))
53
62
  }
54
63
  }
55
- },
56
- ForStatement (path) {
57
- if (path.shouldStopTraverse) {
58
- path.stop()
59
- }
60
- },
61
- // 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
62
- ExportNamedDeclaration (path) {
63
- if (
64
- path.node.declaration &&
65
- path.node.declaration.declarations.length === 1 &&
66
- path.node.declaration.declarations[0].id.name === path.node.declaration.declarations[0].init.name
67
- ) {
68
- const name = path.node.declaration.declarations[0].id.name
69
- path.replaceWith(t.exportNamedDeclaration(undefined, [t.exportSpecifier(t.identifier(name), t.identifier(name))]))
64
+ })
65
+ }
66
+
67
+ if (mode !== 'wx') {
68
+ Object.assign(visitor, {
69
+ CallExpression (path) {
70
+ const callee = path.node.callee
71
+ if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
72
+ const argPath = path.get('arguments')[0]
73
+ if (argPath.isStringLiteral()) {
74
+ argPath.replaceWith(t.stringLiteral(argPath.node.extra.raw.slice(1, -1)))
75
+ }
76
+ }
70
77
  }
71
- }
72
- })
78
+ })
79
+ }
73
80
  }
74
81
 
75
82
  if (mode === 'dd') {
@@ -1,4 +1,4 @@
1
- var camelCase = require('lodash.camelcase')
1
+ const camelCase = require('lodash.camelcase')
2
2
 
3
3
  function dashesCamelCase (str) {
4
4
  return str.replace(/-+(\w)/g, function (match, firstLetter) {
@@ -11,15 +11,15 @@ module.exports = function compileExports (result, importItemMatcher, camelCaseKe
11
11
  return ''
12
12
  }
13
13
 
14
- var exportJs = Object.keys(result.exports).reduce(function (res, key) {
15
- var valueAsString = JSON.stringify(result.exports[key])
14
+ const exportJs = Object.keys(result.exports).reduce(function (res, key) {
15
+ let valueAsString = JSON.stringify(result.exports[key])
16
16
  valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher)
17
17
 
18
18
  function addEntry (k) {
19
19
  res.push('\t' + JSON.stringify(k) + ': ' + valueAsString)
20
20
  }
21
21
 
22
- var targetKey
22
+ let targetKey
23
23
  switch (camelCaseKeys) {
24
24
  case true:
25
25
  addEntry(key)
@@ -6,8 +6,8 @@ module.exports = function createResolver (alias) {
6
6
  }
7
7
 
8
8
  alias = Object.keys(alias).map(function (key) {
9
- var onlyModule = false
10
- var obj = alias[key]
9
+ let onlyModule = false
10
+ let obj = alias[key]
11
11
  if (/\$$/.test(key)) {
12
12
  onlyModule = true
13
13
  key = key.substr(0, key.length - 1)
@@ -26,7 +26,7 @@ module.exports = function createResolver (alias) {
26
26
 
27
27
  return function (url) {
28
28
  alias.forEach(function (obj) {
29
- var name = obj.name
29
+ const name = obj.name
30
30
  if (url === name || (!obj.onlyModule && url.startsWith(name + '/'))) {
31
31
  url = obj.alias + url.substr(name.length)
32
32
  }
@@ -5,12 +5,12 @@
5
5
  */
6
6
  // css base code, injected by the css-loader
7
7
  module.exports = function (useSourceMap) {
8
- var list = []
8
+ const list = []
9
9
 
10
10
  // return the list of modules as css string
11
11
  list.toString = function toString () {
12
12
  return this.map(function (item) {
13
- var content = cssWithMappingToString(item, useSourceMap)
13
+ const content = cssWithMappingToString(item, useSourceMap)
14
14
  if (item[2]) {
15
15
  return '@media ' + item[2] + '{' + content + '}'
16
16
  } else {
@@ -24,15 +24,15 @@ module.exports = function (useSourceMap) {
24
24
  if (typeof modules === 'string') {
25
25
  modules = [[null, modules, '']]
26
26
  }
27
- var alreadyImportedModules = {}
28
- for (var i = 0; i < this.length; i++) {
29
- var id = this[i][0]
27
+ const alreadyImportedModules = {}
28
+ for (let i = 0; i < this.length; i++) {
29
+ const id = this[i][0]
30
30
  if (typeof id === 'number') {
31
31
  alreadyImportedModules[id] = true
32
32
  }
33
33
  }
34
- for (i = 0; i < modules.length; i++) {
35
- var item = modules[i]
34
+ for (let i = 0; i < modules.length; i++) {
35
+ const item = modules[i]
36
36
  // skip already imported module
37
37
  // this implementation is not 100% perfect for weird media query combinations
38
38
  // when a module is imported multiple times with different media queries.
@@ -51,15 +51,15 @@ module.exports = function (useSourceMap) {
51
51
  }
52
52
 
53
53
  function cssWithMappingToString (item, useSourceMap) {
54
- var content = item[1] || ''
55
- var cssMapping = item[3]
54
+ const content = item[1] || ''
55
+ const cssMapping = item[3]
56
56
  if (!cssMapping) {
57
57
  return content
58
58
  }
59
59
 
60
60
  if (useSourceMap && typeof btoa === 'function') {
61
- var sourceMapping = toComment(cssMapping)
62
- var sourceURLs = cssMapping.sources.map(function (source) {
61
+ const sourceMapping = toComment(cssMapping)
62
+ const sourceURLs = cssMapping.sources.map(function (source) {
63
63
  return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
64
64
  })
65
65
 
@@ -72,8 +72,8 @@ function cssWithMappingToString (item, useSourceMap) {
72
72
  // Adapted from convert-source-map (MIT)
73
73
  function toComment (sourceMap) {
74
74
  // eslint-disable-next-line no-undef
75
- var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))
76
- var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64
75
+ const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))
76
+ const data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64
77
77
 
78
78
  return '/*# ' + data + ' */'
79
79
  }
@@ -3,8 +3,8 @@
3
3
  Author Tobias Koppers @sokra
4
4
  Modified by @hiyuki
5
5
  */
6
- var loaderUtils = require('loader-utils')
7
- var path = require('path')
6
+ const loaderUtils = require('loader-utils')
7
+ const path = require('path')
8
8
 
9
9
  module.exports = function getLocalIdent (loaderContext, localIdentName, localName, options) {
10
10
  if (!options.context) {
@@ -16,9 +16,10 @@ module.exports = function getLocalIdent (loaderContext, localIdentName, localNam
16
16
  options.context = loaderContext.context
17
17
  }
18
18
  }
19
- var request = path.relative(options.context, loaderContext.resourcePath)
19
+ const request = path.relative(options.context, loaderContext.resourcePath)
20
20
  options.content = options.hashPrefix + request + '+' + localName
21
21
  localIdentName = localIdentName.replace(/\[local\]/gi, localName)
22
- var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options)
22
+ const hash = loaderUtils.interpolateName(loaderContext, localIdentName, options)
23
+ /* eslint-disable prefer-regex-literals */
23
24
  return hash.replace(new RegExp('[^a-zA-Z0-9\\-_\u00A0-\uFFFF]', 'g'), '-').replace(/^((-?[0-9])|--)/, '_$1')
24
25
  }
@@ -108,7 +108,7 @@ module.exports = function (content, map) {
108
108
  const url = resolve(urlItem.url)
109
109
  idx = url.indexOf('?#')
110
110
  if (idx < 0) idx = url.indexOf('#')
111
- var urlRequest
111
+ let urlRequest
112
112
  if (idx > 0) { // idx === 0 is catched by isUrlRequest
113
113
  // in cases like url('webfont.eot?#iefix')
114
114
  urlRequest = url.substr(0, idx)