cyrilwanner / next-compose-plugins

💡next-compose-plugins provides a cleaner API for enabling and configuring plugins for next.js
MIT License
736 stars 12 forks source link

target server or serverless depending of phase #16

Closed romainquellec closed 5 years ago

romainquellec commented 5 years ago

Hello. My issue is pretty simple. I want to add a property to nextConfig when phase = PHASE_DEVELOPMENT_SERVER.

This is my current next.config.js

require('dotenv').config();

const webpack = require('webpack');
const withPlugins = require('next-compose-plugins')
const withTypescript = require('@zeit/next-typescript')
const withCSS = require('@zeit/next-css')
const withMDX = require('@zeit/next-mdx')()
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');

const nextConfig = {
  target: 'server',
  distDir: 'build',
  generateBuildId: async () => {
    return 'cuistot'
  },
  webpack: (config) => {

    config.plugins.push(
      new SWPrecacheWebpackPlugin({
        verbose: true,
        staticFileGlobsIgnorePatterns: [/build/],
        runtimeCaching: [
          {
            handler: 'networkFirst',
            urlPattern: /^https?.*/
          }
        ]
      })
    )

    config.plugins.push(
      new webpack.EnvironmentPlugin(process.env)
    )

    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
  }
};

module.exports = withPlugins([withTypescript, withMDX, withCSS], nextConfig)

I tried something like this :

module.exports = (phase) => {

  ...

  if(phase === PHASE_DEVELOPMENT_SERVER) {
     nextConfig.target: 'server'
  }
  return config;

...
}

But no effect. Can you help me on this ?

mehrad77 commented 5 years ago

but what you did?!