@mpxjs/webpack-plugin 2.6.115 → 2.7.0-alpha
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/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +58 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +81 -0
- package/lib/dependencies/DynamicEntryDependency.js +171 -0
- package/lib/dependencies/FlagPluginDependency.js +24 -0
- package/lib/dependencies/InjectDependency.js +43 -0
- package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +88 -0
- package/lib/extractor.js +82 -178
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +39 -334
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +889 -525
- package/lib/json-compiler/helper.js +156 -0
- package/lib/json-compiler/index.js +245 -451
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +178 -241
- package/lib/native-loader.js +71 -133
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +14 -2
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +4 -0
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +149 -3
- package/lib/record-loader.js +11 -0
- package/lib/resolve-loader.js +6 -0
- package/lib/resolver/AddEnvPlugin.js +4 -3
- package/lib/resolver/AddModePlugin.js +4 -3
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +23 -36
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/components/web/getInnerListeners.js +1 -3
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +18 -3
- package/lib/runtime/i18n.wxs +31 -11
- package/lib/runtime/optionProcessor.js +48 -3
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/selector.js +29 -10
- package/lib/style-compiler/index.js +16 -24
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/style-compiler/plugins/rpx.js +43 -37
- package/lib/style-compiler/plugins/scope-id.js +79 -72
- package/lib/style-compiler/plugins/trans-special.js +25 -18
- package/lib/style-compiler/plugins/trim.js +13 -7
- package/lib/style-compiler/plugins/vw.js +22 -16
- package/lib/template-compiler/compiler.js +106 -199
- package/lib/template-compiler/index.js +52 -139
- package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
- package/lib/tenon/index.js +105 -0
- package/lib/tenon/processJSON.js +356 -0
- package/lib/tenon/processScript.js +261 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +10 -0
- package/lib/utils/emit-file.js +10 -0
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +13 -0
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/is-url-request.js +10 -1
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -15
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/resolve.js +13 -0
- package/lib/utils/set.js +47 -0
- package/lib/utils/stringify-loaders-resource.js +25 -0
- package/lib/utils/stringify-query.js +4 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +47 -34
- package/lib/web/processTemplate.js +57 -40
- package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
- package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +4 -8
- package/lib/wxs/WxsTemplatePlugin.js +46 -92
- package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
- package/lib/wxs/loader.js +142 -0
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/lib/wxss/processCss.js +107 -103
- package/package.json +21 -18
- package/lib/built-in-loader.js +0 -49
- package/lib/content-loader.js +0 -13
- package/lib/dependency/ChildCompileDependency.js +0 -24
- package/lib/dependency/InjectDependency.js +0 -26
- package/lib/dependency/RemovedModuleDependency.js +0 -23
- package/lib/dependency/ResolveDependency.js +0 -49
- package/lib/path-loader.js +0 -3
- package/lib/plugin-loader.js +0 -287
- package/lib/staticConfig.js +0 -4
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
- package/lib/utils/try-require.js +0 -16
- package/lib/wxs/wxs-loader.js +0 -117
- package/lib/wxss/getImportPrefix.js +0 -30
package/lib/helpers.js
CHANGED
|
@@ -1,375 +1,80 @@
|
|
|
1
|
-
const querystring = require('querystring')
|
|
2
1
|
const loaderUtils = require('loader-utils')
|
|
3
2
|
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')
|
|
13
3
|
const selectorPath = normalize.lib('selector')
|
|
14
|
-
const extractorPath = normalize.lib('extractor')
|
|
15
4
|
const addQuery = require('./utils/add-query')
|
|
16
|
-
|
|
17
|
-
// check whether default js loader exists
|
|
18
|
-
const hasBabel = !!tryRequire('babel-loader')
|
|
19
|
-
|
|
20
|
-
const rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/
|
|
5
|
+
const parseRequest = require('./utils/parse-request')
|
|
21
6
|
|
|
22
7
|
const defaultLang = {
|
|
23
|
-
template: '
|
|
24
|
-
styles: '
|
|
8
|
+
template: 'wxml',
|
|
9
|
+
styles: 'wxss',
|
|
25
10
|
script: 'js',
|
|
26
11
|
json: 'json',
|
|
27
12
|
wxs: 'wxs'
|
|
28
13
|
}
|
|
29
14
|
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
}
|
|
57
|
-
|
|
58
|
-
function ensureBang (loader) {
|
|
59
|
-
if (loader && loader.charAt(loader.length - 1) !== '!') {
|
|
60
|
-
return loader + '!'
|
|
61
|
-
} else {
|
|
62
|
-
return loader
|
|
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
|
-
})
|
|
111
|
-
|
|
112
|
-
function getRequire (type, part, index, scoped) {
|
|
113
|
-
return 'require(' + getRequestString(type, part, index, scoped) + ')'
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function getImport (type, part, index, scoped) {
|
|
117
|
-
return (
|
|
118
|
-
'import __' + type + '__ from ' +
|
|
119
|
-
getRequestString(type, part, index, scoped)
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function getNamedExports (type, part, index, scoped) {
|
|
124
|
-
return (
|
|
125
|
-
'export * from ' +
|
|
126
|
-
getRequestString(type, part, index, scoped)
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function processMode (request, mode) {
|
|
131
|
-
if (mode) {
|
|
132
|
-
// 当前区块如声明了mode则强制覆盖已有request中的mode
|
|
133
|
-
request = addQuery(request, { mode }, true)
|
|
134
|
-
}
|
|
135
|
-
return request
|
|
136
|
-
}
|
|
137
|
-
|
|
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
|
-
}
|
|
15
|
+
module.exports = function createHelpers (loaderContext) {
|
|
16
|
+
const rawRequest = loaderUtils.getRemainingRequest(loaderContext)
|
|
17
|
+
const { resourcePath, queryObj } = parseRequest(loaderContext.resource)
|
|
151
18
|
|
|
152
|
-
function
|
|
153
|
-
return 'require(' +
|
|
19
|
+
function getRequire (type, part, extraOptions, index) {
|
|
20
|
+
return 'require(' + getRequestString(type, part, extraOptions, index) + ')'
|
|
154
21
|
}
|
|
155
22
|
|
|
156
|
-
function
|
|
23
|
+
function getImport (type, part, extraOptions, index) {
|
|
157
24
|
return (
|
|
158
25
|
'import __' + type + '__ from ' +
|
|
159
|
-
|
|
26
|
+
getRequestString(type, part, extraOptions, index)
|
|
160
27
|
)
|
|
161
28
|
}
|
|
162
29
|
|
|
163
|
-
function
|
|
30
|
+
function getNamedExports (type, part, extraOptions, index) {
|
|
164
31
|
return (
|
|
165
32
|
'export * from ' +
|
|
166
|
-
|
|
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)
|
|
33
|
+
getRequestString(type, part, extraOptions, index)
|
|
176
34
|
)
|
|
177
35
|
}
|
|
178
36
|
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
const OPTIONS = {
|
|
186
|
-
localIdentName: '[hash:base64]'
|
|
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
|
-
})
|
|
37
|
+
function getFakeRequest (type, part) {
|
|
38
|
+
const lang = part.lang || defaultLang[type] || type
|
|
39
|
+
const options = { ...queryObj }
|
|
40
|
+
if (lang === 'json') options.asScript = true
|
|
41
|
+
return addQuery(`${resourcePath}.${lang}`, options)
|
|
198
42
|
}
|
|
199
43
|
|
|
200
|
-
function
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
219
|
-
|
|
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
|
|
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
|
-
}
|
|
246
|
-
|
|
247
|
-
function getRawLoaderString (type, part, index, scoped) {
|
|
248
|
-
let lang = (part.lang && part.lang !== config[srcMode].typeExtMap.template.slice(1)) ? part.lang : defaultLang[type]
|
|
249
|
-
|
|
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
|
-
}
|
|
44
|
+
function getRequestString (type, part, extraOptions = {}, index = 0) {
|
|
45
|
+
const src = part.src
|
|
46
|
+
const options = {
|
|
47
|
+
mpx: true,
|
|
48
|
+
type,
|
|
49
|
+
index,
|
|
50
|
+
...extraOptions
|
|
272
51
|
}
|
|
273
52
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
moduleId,
|
|
283
|
-
root: projectRoot
|
|
284
|
-
}
|
|
285
|
-
templateCompiler = templateCompilerPath + '?' + JSON.stringify(templateCompilerOptions)
|
|
53
|
+
switch (type) {
|
|
54
|
+
case 'json':
|
|
55
|
+
options.asScript = true
|
|
56
|
+
if (part.useJSONJS) options.useJSONJS = true
|
|
57
|
+
// eslint-disable-next-line no-fallthrough
|
|
58
|
+
case 'styles':
|
|
59
|
+
case 'template':
|
|
60
|
+
options.extract = true
|
|
286
61
|
}
|
|
287
62
|
|
|
288
|
-
|
|
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
|
-
}
|
|
63
|
+
if (part.mode) options.mode = part.mode
|
|
312
64
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return ensureBang(loader)
|
|
65
|
+
if (src) {
|
|
66
|
+
return loaderUtils.stringifyRequest(loaderContext, addQuery(src, options, true))
|
|
318
67
|
} else {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
|
68
|
+
const fakeRequest = getFakeRequest(type, part)
|
|
69
|
+
const request = `${selectorPath}!${addQuery(rawRequest, options, true)}`
|
|
70
|
+
return loaderUtils.stringifyRequest(loaderContext, `${fakeRequest}!=!${request}`)
|
|
346
71
|
}
|
|
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
|
-
)
|
|
362
72
|
}
|
|
363
73
|
|
|
364
74
|
return {
|
|
365
|
-
loaders,
|
|
366
75
|
getRequire,
|
|
367
76
|
getImport,
|
|
368
77
|
getNamedExports,
|
|
369
|
-
|
|
370
|
-
getImportForSrc,
|
|
371
|
-
getNamedExportsForSrc,
|
|
372
|
-
getRequestString,
|
|
373
|
-
getSrcRequestString
|
|
78
|
+
getRequestString
|
|
374
79
|
}
|
|
375
80
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const parseComponent = require('./parser')
|
|
2
|
+
const createHelpers = require('./helpers')
|
|
3
|
+
const CommonJsVariableDependency = require('./dependencies/CommonJsVariableDependency')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const normalize = require('./utils/normalize')
|
|
6
|
+
|
|
7
|
+
module.exports = function (content) {
|
|
8
|
+
this.cacheable()
|
|
9
|
+
const mpx = this.getMpx()
|
|
10
|
+
if (!mpx) {
|
|
11
|
+
return content
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const mode = mpx.mode
|
|
15
|
+
const env = mpx.env
|
|
16
|
+
const i18n = mpx.i18n
|
|
17
|
+
const filePath = this.resourcePath
|
|
18
|
+
const extname = path.extname(filePath)
|
|
19
|
+
if (extname === '.mpx') {
|
|
20
|
+
const parts = parseComponent(content, {
|
|
21
|
+
filePath,
|
|
22
|
+
needMap: this.sourceMap,
|
|
23
|
+
mode,
|
|
24
|
+
env
|
|
25
|
+
})
|
|
26
|
+
const {
|
|
27
|
+
getRequire
|
|
28
|
+
} = createHelpers(this)
|
|
29
|
+
|
|
30
|
+
if (parts.script) {
|
|
31
|
+
content = getRequire('script', parts.script)
|
|
32
|
+
} else {
|
|
33
|
+
content = ''
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let output = 'global.isIndependent = true\n'
|
|
38
|
+
// 注入i18n
|
|
39
|
+
if (i18n) {
|
|
40
|
+
const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
|
|
41
|
+
const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
|
|
42
|
+
const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
|
|
43
|
+
this._module.addDependency(new CommonJsVariableDependency(i18nWxsRequest))
|
|
44
|
+
// 避免该模块被concatenate导致注入的i18n没有最先执行
|
|
45
|
+
this._module.buildInfo.moduleConcatenationBailout = 'i18n'
|
|
46
|
+
}
|
|
47
|
+
output += content
|
|
48
|
+
output += '\n'
|
|
49
|
+
output += 'delete global.isIndependent\n'
|
|
50
|
+
|
|
51
|
+
return output
|
|
52
|
+
}
|