@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115
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/README.md +1 -1
- package/lib/built-in-loader.js +49 -0
- package/lib/config.js +0 -14
- package/lib/content-loader.js +13 -0
- package/lib/dependency/ChildCompileDependency.js +24 -0
- package/lib/dependency/InjectDependency.js +26 -0
- package/lib/dependency/RemovedModuleDependency.js +23 -0
- package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
- package/lib/dependency/ResolveDependency.js +49 -0
- package/lib/extractor.js +178 -82
- package/lib/file-loader.js +19 -7
- package/lib/helpers.js +334 -39
- package/lib/index.js +525 -889
- package/lib/json-compiler/index.js +451 -245
- package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
- package/lib/loader.js +241 -178
- package/lib/native-loader.js +133 -71
- package/lib/parser.js +2 -1
- package/lib/path-loader.js +3 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +3 -2
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +3 -149
- package/lib/plugin-loader.js +287 -0
- package/lib/resolver/AddEnvPlugin.js +3 -4
- package/lib/resolver/AddModePlugin.js +3 -4
- package/lib/resolver/PackageEntryPlugin.js +36 -23
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/getInnerListeners.js +3 -1
- package/lib/runtime/components/web/mpx-image.vue +5 -20
- package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
- package/lib/runtime/components/web/mpx-swiper.vue +3 -18
- package/lib/runtime/i18n.wxs +11 -31
- package/lib/runtime/optionProcessor.js +3 -48
- package/lib/selector.js +10 -29
- package/lib/staticConfig.js +4 -0
- package/lib/style-compiler/index.js +24 -16
- package/lib/style-compiler/load-postcss-config.js +1 -3
- package/lib/style-compiler/plugins/conditional-strip.js +65 -68
- package/lib/style-compiler/plugins/rpx.js +37 -43
- package/lib/style-compiler/plugins/scope-id.js +72 -79
- package/lib/style-compiler/plugins/trans-special.js +18 -25
- package/lib/style-compiler/plugins/trim.js +7 -13
- package/lib/style-compiler/plugins/vw.js +16 -22
- package/lib/template-compiler/compiler.js +199 -106
- package/lib/template-compiler/index.js +139 -52
- package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
- package/lib/url-loader.js +29 -11
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/get-main-compilation.js +6 -0
- package/lib/utils/is-url-request.js +1 -10
- package/lib/utils/match-condition.js +1 -4
- package/lib/utils/normalize.js +15 -4
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/read-json-for-src.js +34 -0
- package/lib/utils/stringify-query.js +0 -4
- package/lib/utils/try-require.js +16 -0
- package/lib/web/processJSON.js +144 -113
- package/lib/web/processScript.js +34 -47
- package/lib/web/processTemplate.js +40 -57
- package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +8 -4
- package/lib/wxs/WxsTemplatePlugin.js +92 -46
- package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
- package/lib/wxs/wxs-loader.js +117 -0
- package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
- package/lib/wxss/getImportPrefix.js +30 -0
- package/lib/wxss/loader.js +43 -31
- package/lib/wxss/localsLoader.js +5 -1
- package/lib/wxss/processCss.js +103 -107
- package/package.json +18 -21
- package/LICENSE +0 -433
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/dependencies/AppEntryDependency.js +0 -58
- package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
- package/lib/dependencies/CommonJsVariableDependency.js +0 -81
- package/lib/dependencies/DynamicEntryDependency.js +0 -171
- package/lib/dependencies/FlagPluginDependency.js +0 -24
- package/lib/dependencies/InjectDependency.js +0 -43
- package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
- package/lib/dependencies/RecordIndependentDependency.js +0 -44
- package/lib/dependencies/RecordResourceMapDependency.js +0 -62
- package/lib/dependencies/RemoveEntryDependency.js +0 -40
- package/lib/dependencies/ResolveDependency.js +0 -88
- package/lib/independent-loader.js +0 -52
- package/lib/json-compiler/helper.js +0 -156
- package/lib/json-compiler/plugin.js +0 -150
- package/lib/partial-compile/index.js +0 -35
- package/lib/record-loader.js +0 -11
- package/lib/resolve-loader.js +0 -6
- package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
- package/lib/runtime/components/tenon/tenon-button.vue +0 -305
- package/lib/runtime/components/tenon/tenon-image.vue +0 -61
- package/lib/runtime/components/tenon/tenon-input.vue +0 -99
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
- package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
- package/lib/runtime/components/tenon/tenon-text.vue +0 -64
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/tenon/util.js +0 -44
- package/lib/runtime/optionProcessor.tenon.js +0 -386
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -105
- package/lib/tenon/processJSON.js +0 -360
- package/lib/tenon/processScript.js +0 -260
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -133
- package/lib/utils/const.js +0 -10
- package/lib/utils/emit-file.js +0 -10
- package/lib/utils/eval-json-js.js +0 -31
- package/lib/utils/get-entry-name.js +0 -13
- package/lib/utils/get-json-content.js +0 -42
- package/lib/utils/get-relative-path.js +0 -24
- package/lib/utils/resolve.js +0 -13
- package/lib/utils/set.js +0 -47
- package/lib/utils/stringify-loaders-resource.js +0 -25
- package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
- package/lib/wxs/loader.js +0 -142
package/lib/helpers.js
CHANGED
|
@@ -1,80 +1,375 @@
|
|
|
1
|
+
const querystring = require('querystring')
|
|
1
2
|
const loaderUtils = require('loader-utils')
|
|
2
3
|
const normalize = require('./utils/normalize')
|
|
4
|
+
const tryRequire = require('./utils/try-require')
|
|
5
|
+
const styleCompilerPath = normalize.lib('style-compiler/index')
|
|
6
|
+
const templateCompilerPath = normalize.lib('template-compiler/index')
|
|
7
|
+
const jsonCompilerPath = normalize.lib('json-compiler/index')
|
|
8
|
+
const templatePreprocessorPath = normalize.lib('template-compiler/preprocessor')
|
|
9
|
+
const wxsLoaderPath = normalize.lib('wxs/wxs-loader')
|
|
10
|
+
const wxmlLoaderPath = normalize.lib('wxml/wxml-loader')
|
|
11
|
+
const wxssLoaderPath = normalize.lib('wxss/loader')
|
|
12
|
+
const config = require('./config')
|
|
3
13
|
const selectorPath = normalize.lib('selector')
|
|
14
|
+
const extractorPath = normalize.lib('extractor')
|
|
4
15
|
const addQuery = require('./utils/add-query')
|
|
5
|
-
|
|
16
|
+
|
|
17
|
+
// check whether default js loader exists
|
|
18
|
+
const hasBabel = !!tryRequire('babel-loader')
|
|
19
|
+
|
|
20
|
+
const rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/
|
|
6
21
|
|
|
7
22
|
const defaultLang = {
|
|
8
|
-
template: '
|
|
9
|
-
styles: '
|
|
23
|
+
template: 'html',
|
|
24
|
+
styles: 'css',
|
|
10
25
|
script: 'js',
|
|
11
26
|
json: 'json',
|
|
12
27
|
wxs: 'wxs'
|
|
13
28
|
}
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
const postcssExtensions = [
|
|
31
|
+
'postcss', 'pcss', 'sugarss', 'sss'
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
function getRawRequest ({ resource, loaderIndex, loaders }, excludedPreLoaders = /eslint-loader/) {
|
|
35
|
+
return loaderUtils.getRemainingRequest({
|
|
36
|
+
resource: resource,
|
|
37
|
+
loaderIndex: loaderIndex,
|
|
38
|
+
loaders: loaders.filter(loader => !excludedPreLoaders.test(loader.path))
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// sass => sass-loader
|
|
43
|
+
// sass-loader => sass-loader
|
|
44
|
+
// sass?indentedSyntax!css => sass-loader?indentedSyntax&!css-loader
|
|
45
|
+
function ensureLoader (lang) {
|
|
46
|
+
return lang
|
|
47
|
+
.split('!')
|
|
48
|
+
.map(loader =>
|
|
49
|
+
loader.replace(
|
|
50
|
+
/^([\w-]+)(\?.*)?/,
|
|
51
|
+
(_, name, query) =>
|
|
52
|
+
(/-loader$/.test(name) ? name : name + '-loader') + (query || '')
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
.join('!')
|
|
56
|
+
}
|
|
18
57
|
|
|
19
|
-
|
|
20
|
-
|
|
58
|
+
function ensureBang (loader) {
|
|
59
|
+
if (loader && loader.charAt(loader.length - 1) !== '!') {
|
|
60
|
+
return loader + '!'
|
|
61
|
+
} else {
|
|
62
|
+
return loader
|
|
21
63
|
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function resolveLoaders ({ options, projectRoot }) {
|
|
67
|
+
let cssLoaderOptions = ''
|
|
68
|
+
let wxmlLoaderOptions = ''
|
|
69
|
+
let jsonCompilerOptions = ''
|
|
70
|
+
|
|
71
|
+
wxmlLoaderOptions += '?root=' + projectRoot
|
|
72
|
+
jsonCompilerOptions += '?root=' + projectRoot
|
|
73
|
+
// 由于css-loader@1.0之后不再支持root,暂时不允许在css中使用/开头的路径,后续迁移至postcss-loader再进行支持
|
|
74
|
+
// 现在切回css-loader@0.28.11了,先加回来和原生小程序保持一致
|
|
75
|
+
cssLoaderOptions += (cssLoaderOptions ? '&' : '?') + 'root=' + projectRoot + '&extract=true'
|
|
76
|
+
|
|
77
|
+
const defaultLoaders = {
|
|
78
|
+
html: wxmlLoaderPath + wxmlLoaderOptions,
|
|
79
|
+
css: getCSSLoaderString(),
|
|
80
|
+
js: hasBabel ? 'babel-loader' : '',
|
|
81
|
+
json: jsonCompilerPath + jsonCompilerOptions,
|
|
82
|
+
wxs: wxsLoaderPath
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getCSSLoaderString (lang) {
|
|
86
|
+
const langLoader = lang ? ensureBang(ensureLoader(lang)) : ''
|
|
87
|
+
return ensureBang('css-loader' + cssLoaderOptions) + langLoader
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
defaultLoaders,
|
|
92
|
+
getCSSLoaderString,
|
|
93
|
+
loaders: Object.assign({}, defaultLoaders, options.loaders),
|
|
94
|
+
preLoaders: options.preLoaders || {},
|
|
95
|
+
postLoaders: options.postLoaders || {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = function createHelpers ({ loaderContext, options, moduleId, hasScoped, hasComment, usingComponents, srcMode, isNative, projectRoot }) {
|
|
100
|
+
const rawRequest = getRawRequest(loaderContext, options.excludedPreLoaders)
|
|
101
|
+
const {
|
|
102
|
+
defaultLoaders,
|
|
103
|
+
getCSSLoaderString,
|
|
104
|
+
loaders,
|
|
105
|
+
preLoaders,
|
|
106
|
+
postLoaders
|
|
107
|
+
} = resolveLoaders({
|
|
108
|
+
options,
|
|
109
|
+
projectRoot
|
|
110
|
+
})
|
|
22
111
|
|
|
23
|
-
function
|
|
112
|
+
function getRequire (type, part, index, scoped) {
|
|
113
|
+
return 'require(' + getRequestString(type, part, index, scoped) + ')'
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getImport (type, part, index, scoped) {
|
|
24
117
|
return (
|
|
25
118
|
'import __' + type + '__ from ' +
|
|
26
|
-
getRequestString(type, part,
|
|
119
|
+
getRequestString(type, part, index, scoped)
|
|
27
120
|
)
|
|
28
121
|
}
|
|
29
122
|
|
|
30
|
-
function getNamedExports (type, part,
|
|
123
|
+
function getNamedExports (type, part, index, scoped) {
|
|
31
124
|
return (
|
|
32
125
|
'export * from ' +
|
|
33
|
-
getRequestString(type, part,
|
|
126
|
+
getRequestString(type, part, index, scoped)
|
|
34
127
|
)
|
|
35
128
|
}
|
|
36
129
|
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
130
|
+
function processMode (request, mode) {
|
|
131
|
+
if (mode) {
|
|
132
|
+
// 当前区块如声明了mode则强制覆盖已有request中的mode
|
|
133
|
+
request = addQuery(request, { mode }, true)
|
|
134
|
+
}
|
|
135
|
+
return request
|
|
42
136
|
}
|
|
43
137
|
|
|
44
|
-
function getRequestString (type, part,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
138
|
+
function getRequestString (type, part, index = 0, scoped) {
|
|
139
|
+
return loaderUtils.stringifyRequest(
|
|
140
|
+
loaderContext,
|
|
141
|
+
// disable all configuration loaders
|
|
142
|
+
'!!' +
|
|
143
|
+
// get loader string for pre-processors
|
|
144
|
+
getLoaderString(type, part, index, scoped) +
|
|
145
|
+
// select the corresponding part from the mpx file
|
|
146
|
+
getSelectorString(type, index) +
|
|
147
|
+
// the url to the actual mpx file, including remaining requests
|
|
148
|
+
processMode(rawRequest, part.mode)
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getRequireForSrc (type, impt, index, scoped, prefix) {
|
|
153
|
+
return 'require(' + getSrcRequestString(type, impt, index, scoped, prefix) + ')'
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getImportForSrc (type, impt, index, scoped, prefix) {
|
|
157
|
+
return (
|
|
158
|
+
'import __' + type + '__ from ' +
|
|
159
|
+
getSrcRequestString(type, impt, index, scoped, prefix)
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getNamedExportsForSrc (type, impt, index, scoped, prefix) {
|
|
164
|
+
return (
|
|
165
|
+
'export * from ' +
|
|
166
|
+
getSrcRequestString(type, impt, index, scoped, prefix)
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function getSrcRequestString (type, impt, index = 0, scoped, prefix = '!') {
|
|
171
|
+
let loaderString = type === 'script' ? '' : prefix + getLoaderString(type, impt, index, scoped)
|
|
172
|
+
let src = impt.src
|
|
173
|
+
return loaderUtils.stringifyRequest(
|
|
174
|
+
loaderContext,
|
|
175
|
+
loaderString + processMode(src, impt.mode)
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function addCssModulesToLoader (loader, part, index) {
|
|
180
|
+
if (!part.module) return loader
|
|
181
|
+
const option = options.cssModules || {}
|
|
182
|
+
const DEFAULT_OPTIONS = {
|
|
183
|
+
modules: true
|
|
184
|
+
}
|
|
185
|
+
const OPTIONS = {
|
|
186
|
+
localIdentName: '[hash:base64]'
|
|
51
187
|
}
|
|
188
|
+
return loader.replace(/((?:^|!)css(?:-loader)?)(\?[^!]*)?/, (m, $1, $2) => {
|
|
189
|
+
// $1: !css-loader
|
|
190
|
+
// $2: ?a=b
|
|
191
|
+
const query = loaderUtils.parseQuery($2 || '?')
|
|
192
|
+
Object.assign(query, OPTIONS, option, DEFAULT_OPTIONS)
|
|
193
|
+
if (index !== -1) {
|
|
194
|
+
query.localIdentName += '_' + index
|
|
195
|
+
}
|
|
196
|
+
return $1 + '?' + JSON.stringify(query)
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function buildCustomBlockLoaderString (attrs) {
|
|
201
|
+
const noSrcAttrs = Object.assign({}, attrs)
|
|
202
|
+
delete noSrcAttrs.src
|
|
203
|
+
const qs = querystring.stringify(noSrcAttrs)
|
|
204
|
+
return qs ? '?' + qs : qs
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// stringify an Array of loader objects
|
|
208
|
+
function stringifyLoaders (loaders) {
|
|
209
|
+
return loaders
|
|
210
|
+
.map(
|
|
211
|
+
obj =>
|
|
212
|
+
obj && typeof obj === 'object' && typeof obj.loader === 'string'
|
|
213
|
+
? obj.loader +
|
|
214
|
+
(obj.options ? '?' + JSON.stringify(obj.options) : '')
|
|
215
|
+
: obj
|
|
216
|
+
)
|
|
217
|
+
.join('!')
|
|
218
|
+
}
|
|
52
219
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
case 'styles':
|
|
59
|
-
case 'template':
|
|
60
|
-
options.extract = true
|
|
220
|
+
function getLoaderString (type, part, index, scoped) {
|
|
221
|
+
let loader = getRawLoaderString(type, part, index, scoped)
|
|
222
|
+
const lang = getLangString(type, part)
|
|
223
|
+
if (type !== 'script' && type !== 'wxs') {
|
|
224
|
+
loader = getExtractorString(type, index) + loader
|
|
61
225
|
}
|
|
226
|
+
if (preLoaders[lang]) {
|
|
227
|
+
loader = loader + ensureBang(preLoaders[lang])
|
|
228
|
+
}
|
|
229
|
+
if (postLoaders[lang]) {
|
|
230
|
+
loader = ensureBang(postLoaders[lang]) + loader
|
|
231
|
+
}
|
|
232
|
+
return loader
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function getLangString (type, { lang }) {
|
|
236
|
+
if (type === 'script' || type === 'template' || type === 'styles') {
|
|
237
|
+
return lang || defaultLang[type]
|
|
238
|
+
} else {
|
|
239
|
+
return type
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function replaceCssLoader (rawLoader) {
|
|
244
|
+
return rawLoader.replace(/css(?:-loader)?/, wxssLoaderPath)
|
|
245
|
+
}
|
|
62
246
|
|
|
63
|
-
|
|
247
|
+
function getRawLoaderString (type, part, index, scoped) {
|
|
248
|
+
let lang = (part.lang && part.lang !== config[srcMode].typeExtMap.template.slice(1)) ? part.lang : defaultLang[type]
|
|
64
249
|
|
|
65
|
-
|
|
66
|
-
|
|
250
|
+
let styleCompiler = ''
|
|
251
|
+
if (type === 'styles') {
|
|
252
|
+
// style compiler that needs to be applied for all styles
|
|
253
|
+
styleCompiler = styleCompilerPath + '?' +
|
|
254
|
+
JSON.stringify({
|
|
255
|
+
moduleId,
|
|
256
|
+
scoped: !!scoped
|
|
257
|
+
})
|
|
258
|
+
// normalize scss/sass/postcss if no specific loaders have been provided
|
|
259
|
+
if (!loaders[lang]) {
|
|
260
|
+
if (postcssExtensions.indexOf(lang) !== -1) {
|
|
261
|
+
lang = 'css'
|
|
262
|
+
} else if (lang === 'sass') {
|
|
263
|
+
lang = `sass?${JSON.stringify({
|
|
264
|
+
sassOptions: {
|
|
265
|
+
indentedSyntax: true
|
|
266
|
+
}
|
|
267
|
+
})}`
|
|
268
|
+
} else if (lang === 'scss') {
|
|
269
|
+
lang = 'sass'
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let templateCompiler = ''
|
|
275
|
+
|
|
276
|
+
if (type === 'template') {
|
|
277
|
+
const templateCompilerOptions = {
|
|
278
|
+
usingComponents,
|
|
279
|
+
hasScoped,
|
|
280
|
+
hasComment,
|
|
281
|
+
isNative,
|
|
282
|
+
moduleId,
|
|
283
|
+
root: projectRoot
|
|
284
|
+
}
|
|
285
|
+
templateCompiler = templateCompilerPath + '?' + JSON.stringify(templateCompilerOptions)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let loader = type === 'styles'
|
|
289
|
+
? loaders[lang] || getCSSLoaderString(lang)
|
|
290
|
+
: loaders[lang]
|
|
291
|
+
|
|
292
|
+
if (loader != null) {
|
|
293
|
+
if (Array.isArray(loader)) {
|
|
294
|
+
loader = stringifyLoaders(loader)
|
|
295
|
+
} else if (typeof loader === 'object') {
|
|
296
|
+
loader = stringifyLoaders([loader])
|
|
297
|
+
}
|
|
298
|
+
if (type === 'styles') {
|
|
299
|
+
// add css modules
|
|
300
|
+
loader = addCssModulesToLoader(loader, part, index)
|
|
301
|
+
// inject rewriter before css loader for extractTextPlugin use cases
|
|
302
|
+
if (rewriterInjectRE.test(loader)) {
|
|
303
|
+
loader = loader.replace(
|
|
304
|
+
rewriterInjectRE,
|
|
305
|
+
(m, $1) => ensureBang($1) + ensureBang(styleCompiler)
|
|
306
|
+
)
|
|
307
|
+
} else {
|
|
308
|
+
loader = ensureBang(loader) + ensureBang(styleCompiler)
|
|
309
|
+
}
|
|
310
|
+
loader = replaceCssLoader(loader)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (type === 'template') {
|
|
314
|
+
loader = ensureBang(loader) + ensureBang(templateCompiler)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return ensureBang(loader)
|
|
67
318
|
} else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
319
|
+
// unknown lang, infer the loader to be used
|
|
320
|
+
switch (type) {
|
|
321
|
+
case 'template':
|
|
322
|
+
// allow passing options to the template preprocessor via `templateOption` option
|
|
323
|
+
const preprocessorOption = { engine: lang, templateOption: options.templateOption || {} }
|
|
324
|
+
const templatePreprocessor = templatePreprocessorPath + '?' + JSON.stringify(preprocessorOption)
|
|
325
|
+
return ensureBang(defaultLoaders.html) + ensureBang(templateCompiler) + ensureBang(templatePreprocessor)
|
|
326
|
+
case 'styles':
|
|
327
|
+
loader = addCssModulesToLoader(defaultLoaders.css, part, index)
|
|
328
|
+
loader = replaceCssLoader(loader)
|
|
329
|
+
return ensureBang(loader) + ensureBang(styleCompiler) + ensureBang(ensureLoader(lang))
|
|
330
|
+
case 'script':
|
|
331
|
+
return ensureBang(defaultLoaders.js) + ensureBang(ensureLoader(lang))
|
|
332
|
+
default:
|
|
333
|
+
loader = loaders[type]
|
|
334
|
+
if (Array.isArray(loader)) {
|
|
335
|
+
loader = stringifyLoaders(loader)
|
|
336
|
+
}
|
|
337
|
+
return ensureBang(loader + buildCustomBlockLoaderString(part.attrs))
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function getSelectorString (type, index) {
|
|
343
|
+
const selectorOptions = {
|
|
344
|
+
type,
|
|
345
|
+
index
|
|
71
346
|
}
|
|
347
|
+
return ensureBang(
|
|
348
|
+
selectorPath + '?' +
|
|
349
|
+
JSON.stringify(selectorOptions)
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function getExtractorString (type, index) {
|
|
354
|
+
const extractorOptions = {
|
|
355
|
+
type,
|
|
356
|
+
index
|
|
357
|
+
}
|
|
358
|
+
return ensureBang(
|
|
359
|
+
extractorPath + '?' +
|
|
360
|
+
JSON.stringify(extractorOptions)
|
|
361
|
+
)
|
|
72
362
|
}
|
|
73
363
|
|
|
74
364
|
return {
|
|
365
|
+
loaders,
|
|
75
366
|
getRequire,
|
|
76
367
|
getImport,
|
|
77
368
|
getNamedExports,
|
|
78
|
-
|
|
369
|
+
getRequireForSrc,
|
|
370
|
+
getImportForSrc,
|
|
371
|
+
getNamedExportsForSrc,
|
|
372
|
+
getRequestString,
|
|
373
|
+
getSrcRequestString
|
|
79
374
|
}
|
|
80
375
|
}
|