aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue-loader/lib/codegen
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue-loader/lib/codegen
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vue-loader/lib/codegen')
-rw-r--r--node_modules/vue-loader/lib/codegen/customBlocks.js21
-rw-r--r--node_modules/vue-loader/lib/codegen/hotReload.js31
-rw-r--r--node_modules/vue-loader/lib/codegen/styleInjection.js114
-rw-r--r--node_modules/vue-loader/lib/codegen/utils.js25
4 files changed, 191 insertions, 0 deletions
diff --git a/node_modules/vue-loader/lib/codegen/customBlocks.js b/node_modules/vue-loader/lib/codegen/customBlocks.js
new file mode 100644
index 00000000..64e78a16
--- /dev/null
+++ b/node_modules/vue-loader/lib/codegen/customBlocks.js
@@ -0,0 +1,21 @@
+const qs = require('querystring')
+const { attrsToQuery } = require('./utils')
+
+module.exports = function genCustomBlocksCode (
+ blocks,
+ resourcePath,
+ resourceQuery,
+ stringifyRequest
+) {
+ return `\n/* custom blocks */\n` + blocks.map((block, i) => {
+ const src = block.attrs.src || resourcePath
+ const attrsQuery = attrsToQuery(block.attrs)
+ const issuerQuery = block.attrs.src ? `&issuerPath=${qs.escape(resourcePath)}` : ''
+ const inheritQuery = resourceQuery ? `&${resourceQuery.slice(1)}` : ''
+ const query = `?vue&type=custom&index=${i}&blockType=${qs.escape(block.type)}${issuerQuery}${attrsQuery}${inheritQuery}`
+ return (
+ `import block${i} from ${stringifyRequest(src + query)}\n` +
+ `if (typeof block${i} === 'function') block${i}(component)`
+ )
+ }).join(`\n`) + `\n`
+}
diff --git a/node_modules/vue-loader/lib/codegen/hotReload.js b/node_modules/vue-loader/lib/codegen/hotReload.js
new file mode 100644
index 00000000..4f426b4d
--- /dev/null
+++ b/node_modules/vue-loader/lib/codegen/hotReload.js
@@ -0,0 +1,31 @@
+const hotReloadAPIPath = JSON.stringify(require.resolve('vue-hot-reload-api'))
+
+const genTemplateHotReloadCode = (id, request) => {
+ return `
+ module.hot.accept(${request}, function () {
+ api.rerender('${id}', {
+ render: render,
+ staticRenderFns: staticRenderFns
+ })
+ })
+ `.trim()
+}
+
+exports.genHotReloadCode = (id, functional, templateRequest) => {
+ return `
+/* hot reload */
+if (module.hot) {
+ var api = require(${hotReloadAPIPath})
+ api.install(require('vue'))
+ if (api.compatible) {
+ module.hot.accept()
+ if (!module.hot.data) {
+ api.createRecord('${id}', component.options)
+ } else {
+ api.${functional ? 'rerender' : 'reload'}('${id}', component.options)
+ }
+ ${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
+ }
+}
+ `.trim()
+}
diff --git a/node_modules/vue-loader/lib/codegen/styleInjection.js b/node_modules/vue-loader/lib/codegen/styleInjection.js
new file mode 100644
index 00000000..b11e488a
--- /dev/null
+++ b/node_modules/vue-loader/lib/codegen/styleInjection.js
@@ -0,0 +1,114 @@
+const { attrsToQuery } = require('./utils')
+const hotReloadAPIPath = JSON.stringify(require.resolve('vue-hot-reload-api'))
+
+module.exports = function genStyleInjectionCode (
+ loaderContext,
+ styles,
+ id,
+ resourcePath,
+ stringifyRequest,
+ needsHotReload,
+ needsExplicitInjection
+) {
+ let styleImportsCode = ``
+ let styleInjectionCode = ``
+ let cssModulesHotReloadCode = ``
+
+ let hasCSSModules = false
+ const cssModuleNames = new Map()
+
+ function genStyleRequest (style, i) {
+ const src = style.src || resourcePath
+ const attrsQuery = attrsToQuery(style.attrs, 'css')
+ const inheritQuery = `&${loaderContext.resourceQuery.slice(1)}`
+ // make sure to only pass id when necessary so that we don't inject
+ // duplicate tags when multiple components import the same css file
+ const idQuery = style.scoped ? `&id=${id}` : ``
+ const query = `?vue&type=style&index=${i}${idQuery}${attrsQuery}${inheritQuery}`
+ return stringifyRequest(src + query)
+ }
+
+ function genCSSModulesCode (style, request, i) {
+ hasCSSModules = true
+
+ const moduleName = style.module === true ? '$style' : style.module
+ if (cssModuleNames.has(moduleName)) {
+ loaderContext.emitError(`CSS module name ${moduleName} is not unique!`)
+ }
+ cssModuleNames.set(moduleName, true)
+
+ // `(vue-)style-loader` exports the name-to-hash map directly
+ // `css-loader` exports it in `.locals`
+ const locals = `(style${i}.locals || style${i})`
+ const name = JSON.stringify(moduleName)
+
+ if (!needsHotReload) {
+ styleInjectionCode += `this[${name}] = ${locals}\n`
+ } else {
+ styleInjectionCode += `
+ cssModules[${name}] = ${locals}
+ Object.defineProperty(this, ${name}, {
+ get: function () {
+ return cssModules[${name}]
+ }
+ })
+ `
+ cssModulesHotReloadCode += `
+ module.hot && module.hot.accept([${request}], function () {
+ var oldLocals = cssModules[${name}]
+ if (oldLocals) {
+ var newLocals = require(${request})
+ if (JSON.stringify(newLocals) !== JSON.stringify(oldLocals)) {
+ cssModules[${name}] = newLocals
+ require(${hotReloadAPIPath}).rerender("${id}")
+ }
+ }
+ })
+ `
+ }
+ }
+
+ // explicit injection is needed in SSR (for critical CSS collection)
+ // or in Shadow Mode (for injection into shadow root)
+ // In these modes, vue-style-loader exports objects with the __inject__
+ // method; otherwise we simply import the styles.
+ if (!needsExplicitInjection) {
+ styles.forEach((style, i) => {
+ const request = genStyleRequest(style, i)
+ styleImportsCode += `import style${i} from ${request}\n`
+ if (style.module) genCSSModulesCode(style, request, i)
+ })
+ } else {
+ styles.forEach((style, i) => {
+ const request = genStyleRequest(style, i)
+ styleInjectionCode += (
+ `var style${i} = require(${request})\n` +
+ `if (style${i}.__inject__) style${i}.__inject__(context)\n`
+ )
+ if (style.module) genCSSModulesCode(style, request, i)
+ })
+ }
+
+ if (!needsExplicitInjection && !hasCSSModules) {
+ return styleImportsCode
+ }
+
+ return `
+${styleImportsCode}
+${hasCSSModules && needsHotReload ? `var cssModules = {}` : ``}
+${needsHotReload ? `var disposed = false` : ``}
+
+function injectStyles (context) {
+ ${needsHotReload ? `if (disposed) return` : ``}
+ ${styleInjectionCode}
+}
+
+${needsHotReload ? `
+ module.hot && module.hot.dispose(function (data) {
+ disposed = true
+ })
+` : ``}
+
+${cssModulesHotReloadCode}
+ `.trim()
+}
diff --git a/node_modules/vue-loader/lib/codegen/utils.js b/node_modules/vue-loader/lib/codegen/utils.js
new file mode 100644
index 00000000..054f9a9c
--- /dev/null
+++ b/node_modules/vue-loader/lib/codegen/utils.js
@@ -0,0 +1,25 @@
+const qs = require('querystring')
+
+// these are built-in query parameters so should be ignored
+// if the user happen to add them as attrs
+const ignoreList = [
+ 'id',
+ 'index',
+ 'src',
+ 'type'
+]
+
+// transform the attrs on a SFC block descriptor into a resourceQuery string
+exports.attrsToQuery = (attrs, langFallback) => {
+ let query = ``
+ for (const name in attrs) {
+ const value = attrs[name]
+ if (!ignoreList.includes(name)) {
+ query += `&${qs.escape(name)}=${value ? qs.escape(value) : ``}`
+ }
+ }
+ if (langFallback && !(`lang` in attrs)) {
+ query += `&lang=${langFallback}`
+ }
+ return query
+}