vue中webpack加载html

别开诚
2023-12-01
Vue.use(Router)
let context=require.context('../../static/',true,/\.html$/i)
let pages=[]
context.keys().forEach(item=>{
  let path='../../static/html'+item.slice(1)
  let split=item.split('/')
  let name=split[split.length-1].slice(0,-5)
  let page={
    path,
    name
  }
  pages.push(page)
})

 

如果html文件在static文件夹中,则在webpack.base.conf.js中添加以下配置
module: {
  rules: [
    {
      test:/\.html$/,
      include:function(content){
        return /static/.test(content);
      },
      use:{
        loader:'url-loader',
        options:{
          cacheDirectory:true
        }
      }
    }]
},

 

 类似资料: