如何从 javascript 读取 mix-manifest.json
How to read mix-manifest.json from javascript
我使用 laravel-mix 缓存了我的图像。对于 blade 中的图像,它有效。但是我无法弄清楚如何从 javascript.
访问该版本化路径
是否可以从已编译的 javascript 中读取 mix-manifest.json
?这样我就可以创建一个 mixin 并获取版本化路径
例如,在我的 mix-manifest.json 我有
"/images/hello.svg": "/images/hello.svg?id=0360de485c68385550da",
我想如果我可以从编译的 javascript 中读取 mix-manifest.json
,我可以创建一个像
这样的辅助方法
export default {
methods: {
mixPath(path) {
let manifestObj = // read mix-manifest.json
return manifestObj[path];
}
}
}
我可以使用
访问 mix-manifest.json
const vm = this;
if (!Vue.prototype.BROWSER_BUILD) {
let path = require("path");
this.manifestPaths = JSON.parse(require('fs').readFileSync(path.resolve('./mix-manifest.json'), 'utf8'));
} else {
axios.get('/mix-manifest.json').then(json => {
vm.manifestPaths = json.data
})
}
以及方法:
methods: {
mix(path) {
if (typeof this.manifestPaths[path] == 'undefined') {
return this.manifestPaths[path];
}
return path;
}
}
如果你知道更好的方法,我很乐意知道:)
我使用 laravel-mix 缓存了我的图像。对于 blade 中的图像,它有效。但是我无法弄清楚如何从 javascript.
访问该版本化路径是否可以从已编译的 javascript 中读取 mix-manifest.json
?这样我就可以创建一个 mixin 并获取版本化路径
例如,在我的 mix-manifest.json 我有
"/images/hello.svg": "/images/hello.svg?id=0360de485c68385550da",
我想如果我可以从编译的 javascript 中读取 mix-manifest.json
,我可以创建一个像
export default {
methods: {
mixPath(path) {
let manifestObj = // read mix-manifest.json
return manifestObj[path];
}
}
}
我可以使用
访问 mix-manifest.jsonconst vm = this;
if (!Vue.prototype.BROWSER_BUILD) {
let path = require("path");
this.manifestPaths = JSON.parse(require('fs').readFileSync(path.resolve('./mix-manifest.json'), 'utf8'));
} else {
axios.get('/mix-manifest.json').then(json => {
vm.manifestPaths = json.data
})
}
以及方法:
methods: {
mix(path) {
if (typeof this.manifestPaths[path] == 'undefined') {
return this.manifestPaths[path];
}
return path;
}
}
如果你知道更好的方法,我很乐意知道:)