Nuxt js。是否可以为_nuxt文件夹中生成的js文件设置自定义路径?

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

最近我开始了一个使用 Nuxt js 的项目。但是因为公司与另一个应用程序使用同一服务器,并且 url

https://my-company.com/_nuxt/
URL 路径已被另一个应用程序使用,所以我必须将
/customprefix/
添加到应用程序路径中。所以预期的路径 URL 是
https://my-company.com/customprefix/_nuxt/
.

我已经尝试添加

publicPath
,就像在这个问题中接受的答案中提到的那样,并在应用程序的根目录中创建一个名为
customprefix
的文件夹,但文件仍然在
https://my-company.com/_nuxt/

中生成

这是我当前的

nuxt.config.js
文件


export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  
  build:{
    publicPath: "/customprefix"
  },
  static:{
    prefix: true
  },
  
  head: {
    titleTemplate: '%s - nuxt-test',
    title: 'nuxt-test',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/vuetify
    '@nuxtjs/vuetify',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
  ],

  // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    theme: {
      dark: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3
        }
      }
    }
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
  }
}

非常感谢任何帮助。

javascript nuxt.js
3个回答
0
投票

我刚刚找到了解决方案。原来我需要做的是设置路由器上的 base 属性

我的最终

nuxt.config.js
文件:

import colors from 'vuetify/es5/util/colors'

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  router:{
    base:"/customprefix/"
  },
  static:{
    prefix: true
  },
  
  head: {
    titleTemplate: '%s - nuxt-test',
    title: 'nuxt-test',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/vuetify
    '@nuxtjs/vuetify',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
  ],

  // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    theme: {
      dark: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3
        }
      }
    }
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
  }
}

我补充的是:

 router:{
    base:"/customprefix/"
  },

0
投票

你可以试试这个

build: {
  publicPath: '/your-customprefix/'
},

0
投票

每次更新后,请确保删除“node_modules”文件夹和“package-lock.json”文件,并在“nuxt.config.js”中添加kissu提到的代码

© www.soinside.com 2019 - 2024. All rights reserved.