1 Star 0 Fork 0

jaawu/webpack-mpvue-asset-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
许涛 提交于 2019-02-01 12:19 . resolve issue #1366
const path = require('path')
const upath = require('upath')
const relative = require('relative')
const getRelativePath = (filePath) => {
if (!/^\.(\.)?\//.test(filePath)) {
filePath = `./${filePath}`
}
return filePath
}
const emitHandle = (compilation, callback) => {
Object.keys(compilation.entrypoints).forEach(key => {
const { chunks } = compilation.entrypoints[key]
const entryChunk = chunks.pop()
entryChunk.files.forEach(filePath => {
const assetFile = compilation.assets[filePath]
const extname = path.extname(filePath)
let content = assetFile.source()
chunks.reverse().forEach(chunk => {
chunk.files.forEach(subFile => {
if (path.extname(subFile) === extname && assetFile) {
let relativePath = upath.normalize(relative(filePath, subFile))
// 百度小程序 js 引用不支持绝对路径,改为相对路径
if (extname === '.js') {
relativePath = getRelativePath(relativePath)
}
if (/^(\.wxss)|(\.ttss)|(\.acss)|(\.css)$/.test(extname)) {
relativePath = getRelativePath(relativePath)
content = `@import "${relativePath}";\n${content}`
} else if (!(/^\.map$/.test(extname))) {
content = `require("${relativePath}")\n${content}`
}
}
})
assetFile.source = () => content
})
})
})
callback()
}
function MpvuePlugin() {}
MpvuePlugin.prototype.apply = compiler => compiler.plugin('emit', emitHandle)
module.exports = MpvuePlugin
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jaawu/webpack-mpvue-asset-plugin.git
git@gitee.com:jaawu/webpack-mpvue-asset-plugin.git
jaawu
webpack-mpvue-asset-plugin
webpack-mpvue-asset-plugin
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385