Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compiler.hooks.invalid.tap('webpack-uni-mp-invalid', (fileName, changeTime) => {
if (
fileName &&
typeof fileName === 'string'
) { // 重新解析 entry
const basename = path.basename(fileName)
const deps = process.UNI_PAGES_DEPS || new Set()
if (
basename === 'pages.json' ||
basename === pagesJsonJsFileName ||
deps.has(normalizePath(fileName))
) {
try {
parseEntry()
} catch (e) {
console.error(e)
}
}
}
})
}
Object.keys(process.UNI_SUBPACKAGES).forEach(root => {
const subPackageVendorPath = normalizePath(path.join(root, 'common/vendor.js'))
if (assetsKeys.indexOf(subPackageVendorPath) !== -1) {
// TODO 理论上仅需在分包第一个 js 中添加 require common vendor,但目前不同平台可能顺序不一致,
// 故 每个分包里的 js 里均添加一次 require
assetsKeys.forEach(name => {
if (
path.extname(name) === '.js' &&
name.indexOf(root) === 0 &&
name !== subPackageVendorPath
) {
const source = `require('${normalizePath(path.relative(path.dirname(name), subPackageVendorPath))}');` +
compilation.assets[name].source()
compilation.assets[name] = {
size () {
return Buffer.byteLength(source, 'utf8')
},
function baseTest (module) {
if (module.type === 'css/mini-extract') {
return false
}
if (module.resource) {
const resource = normalizePath(module.resource)
if (
resource.indexOf('.vue') !== -1 ||
resource.indexOf('.nvue') !== -1 ||
resource.indexOf(mainPath) === 0 // main.js
) {
return false
}
}
return true
}
// TODO 独立分包
module.exports = function(content, map) {
this.cacheable && this.cacheable()
const resourcePath = removeExt(
normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
)
content = content + getUsingComponentsCode(resourcePath)
// TODO 自动导入 vue 组件(h5,小程序,app[vue,nvue])
// 1. 需要 template-loader 解析出所有自定义组件()
// 2. 根据自定义组件信息生成引用代码
// 3. node-modules中的组件不提供自动导入
return content
}
const path = require('path')
const {
removeExt,
normalizePath
} = require('@dcloudio/uni-cli-shared')
const {
getComponentSet
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
restoreNodeModules
} = require('../shared')
const uniPath = normalizePath(require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM))
function findModule (modules, resource, altResource) {
return modules.find(
module => {
let moduleResource = module.resource
if (
!moduleResource ||
(
moduleResource.indexOf('.vue') === -1 &&
moduleResource.indexOf('.nvue') === -1
)
) {
return
}
moduleResource = removeExt(module.resource)
return moduleResource === resource || moduleResource === altResource
}, function (root, page) {
updatePageJson(normalizePath(path.join(root, page.path)), renameUsingComponents(
parseStyle(page.style, root)
))
})
addDependency: (file) => {
(process.UNI_PAGES_DEPS || (process.UNI_PAGES_DEPS = new Set())).add(normalizePath(file))
this.addDependency(file)
}
})
}, function (root, page) {
checkPageEmitFile(normalizePath(path.join(root, page.path)), page.style)
})
function genStyleRequest(style, i, stringifyRequest) {
const src = style.src || normalizePath(appVuePath)
const attrsQuery = attrsToQuery(style.attrs, 'css')
const query = `?vue&type=style&index=${i}${attrsQuery}`
return stringifyRequest(src + query)
}