在nuxt中公开静态资产

问题描述 投票:0回答:2

我正在尝试将bootstrap主题重构为一个nuxt项目。我想从静态文件夹提供静态文件,如下所示:

enter image description here

在我的nuxt.config文件中,我有:

head: {
title: pkg.name,
meta: [
  { charset: 'utf-8' },
  { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  { hid: 'description', name: 'description', content: pkg.description },
],
link: [
  { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
  { rel: 'stylesheet',  href: '/static/css/fancybox/jquery.fancybox.css' },
  { rel: 'stylesheet',  href: '/static/css/bootstrap.css' },
  { rel: 'stylesheet',  href: '/css/bootstrap-theme.css' },
  { rel: 'stylesheet',  href: '/css/slippry.css' },
  { rel: 'stylesheet',  href: '/static/css/style.css' },
  { rel: 'stylesheet',  href: '/static/color/default.css' },
],
script:[{'src': 'static/js/modernizr.custom.js' }]

},

但是在我的开发工具中,我看到:

enter image description here

我读过https://nuxtjs.org/guide/assets/,但仍不清楚如何提供这些资产

我怎样才能使这个工作?

编辑:按照你的指示,我现在有:

head: {
title: pkg.name,
meta: [
  { charset: 'utf-8' },
  { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  { hid: 'description', name: 'description', content: pkg.description },
],
link: [
  { rel: 'icon', type: 'image/x-icon', href: '~assets/favicon.ico' },
  { rel: 'stylesheet',  href: '~assets/css/fancybox/jquery.fancybox.css' },
  { rel: 'stylesheet',  href: '~assets/css/bootstrap.css' },
  { rel: 'stylesheet',  href: '~assets/css/bootstrap-theme.css' },
  { rel: 'stylesheet',  href: '~assets/css/slippry.css' },
  { rel: 'stylesheet',  href: '~assets/css/style.css' },
  { rel: 'stylesheet',  href: '~assets/color/default.css' },
],
script:[{'src': '~assets/js/modernizr.custom.js' }]

 },

我的目录结构:

enter image description here

但是,当我尝试:

$npm run dev

我知道了:

enter image description here

javascript vue.js nuxt
2个回答
1
投票

将静态文件夹重命名为assets文件夹,并使用〜assets / path-to-your-file引用它。 https://nuxtjs.org/guide/assets/


0
投票

如果使用静态文件夹,则根域中的所有资产都可用。见docs

所以你的配置都需要像这样:

  { rel: 'stylesheet',  href: '/css/fancybox/jquery.fancybox.css' },
  { rel: 'stylesheet',  href: '/css/bootstrap.css' },

最佳实践

但是你应该通过nuxt编译这个css,只需将它们添加到nuxt配置中的css property即可。

  css: [
   '@/assets/css/fancybox/jquery.fancybox.css',
   '@/assets/css/bootstrap.css'
  ],
© www.soinside.com 2019 - 2024. All rights reserved.