我从vue和nuxt开始,我有一个使用vuetify的项目,并且试图修改轮播组件以从静态文件夹动态加载图像。到目前为止,我已经提出了:
<template>
<v-carousel>
<v-carousel-item v-for="(item,i) in items" :key="i" :src="item.src"></v-carousel-item>
</v-carousel>
</template>
<script>
function getImagePaths() {
var glob = require("glob");
var options = {
cwd: "./static"
};
var fileNames = glob.sync("*", options);
var items = [];
fileNames.forEach(fileName =>
items.push({
'src': '/'+fileName
})
);
return items;
}
export default {
data() {
return {items :getImagePaths()};
}
};
</script>
当我对此进行测试时,我看到:
ERROR in ./node_modules/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in '....\node_modules\fs.realpath'
ERROR in ./node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in ....\node_modules\fs.realpath'
ERROR in ./node_modules/glob/glob.js
Module not found: Error: Can't resolve 'fs' in '....\node_modules\glob'
ERROR in ./node_modules/glob/sync.js
Module not found: Error: Can't resolve 'fs' in '.....\node_modules\glob'
谷歌搜索我看到一堆参考,如https://github.com/webpack-contrib/css-loader/issues/447。
这些建议您必须使用类似以下内容来简化webpack配置文件:
node: {
fs: 'empty'
}
我对webpack知之甚少。我找到了https://nuxtjs.org/faq/extend-webpack/,但是不确定这种情况下如何修改webpack配置文件。
我该怎么做呢?