如何在next.config.js中结合这2条语句以进行部署

时间:2019-07-08 13:08:17

标签: webpack next.js

我正在将一个Nextjs应用程序部署到Zeit,但是根据它要求添加的文档

module.exports = {
  target: 'serverless'
}

与next.config.js中一样

但是我的文件已经包含module.export

const withCSS = require('@zeit/next-css')

module.exports = withCSS({
  webpack: function (config) {
    config.module.rules.push({
      test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
      use: {
        loader: 'url-loader',
        options: {
          limit: 100000,
          name: '[name].[ext]'
        },
      },   
    },
    )
    return config
  }
},

)

如何将这些出口合并为一个。请帮帮我!

我尝试做过本期https://github.com/zeit/next-plugins/issues/34https://github.com/zeit/next-plugins/issues/7的建议

但是withCSS({})

尚无示例

2 个答案:

答案 0 :(得分:2)

您应该能够像这样组合它们:

const withCSS = require('@zeit/next-css')

module.exports = withCSS({
  target: 'serverless',
  webpack: function (config) {
    config.module.rules.push({
      test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
      use: {
        loader: 'url-loader',
        options: {
          limit: 100000,
          name: '[name].[ext]'
        },
      },   
    },
    )
    return config
  }
})

答案 1 :(得分:0)

使用这个可爱的插件https://github.com/JerryCauser/next-compose 结合

例如:

const withTS = require('@zeit/next-typescript')
const withSass = require('@zeit/next-sass')
const compose = require('next-compose')

const tsConfig = {/** ts config here */}
const sassConfig = {/** sass config here */}

module.exports = compose([
  [withTS, tsConfig],
  [withSass, sassConfig],
  {
    webpack: (config) => {
      /**some special code */
      return config
    }
  }
])