简体   繁体   English

module.exports 和 nuxt 中的导出默认值

[英]module.exports and export default in nuxt

In the past days I have kind of a headache with this and it's surely due to my lack of experience.在过去的几天里,我对此有点头疼,这肯定是由于我缺乏经验。 I recently started using nuxt and nuxt modules.我最近开始使用nuxtnuxt模块。

As I use the command yarn create nuxt-app my-project , the nuxt.config.js file is populated with module.exports .当我使用命令yarn create nuxt-app my-projectnuxt.config.js文件填充了module.exports My problem is that when I was installing certain modules, the configuration was only working in export default .我的问题是,当我安装某些模块时,配置仅适用于export default I have for example the following config:例如,我有以下配置:

  build: {
      extend (config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }

This configuration only works inside export default but not when I write it in module.exports , I have no clue about the reason.此配置仅在export default但在我将其写入module.exports ,我不知道原因。

Another example is with head , let's say the following code:另一个例子是head ,让我们说下面的代码:

  head: {
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }
    ]
  },

When I put it in export default , it doesn't work, and in module.exports it works.当我将它放入export default ,它不起作用,而在module.exports它起作用。 So, until now I'm doing trial and error depending where it works.所以,直到现在我都在反复试验,这取决于它在哪里工作。

I know that there is a reference in the question module.exports vs. export default in Node.js and ES6 .我知道在问题module.exports vs. export default in Node.js 和 ES6中有一个参考。 However it's not yet clear to me why some stuff work in module.exports and some other stuff in export default .然而,我还不清楚为什么有些东西在module.exportsmodule.exports而有些东西在export defaultmodule.exports

Some explanation would be highly appreciated.一些解释将不胜感激。

我有一个类似的问题......试图影响'禁用 Nuxt/no-cjs-in-config for this line' 以便能够使用module.exports =但它在我运行时继续恢复为export default firebase deploy --only functions在我的终端中运行并抛出语法错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM