Как добавить более двух плагинов в next.config.js - PullRequest
0 голосов
/ 10 февраля 2019

Я хотел внедрить методологию sass и BEM в проект нашей компании, однако у меня возникли небольшие проблемы с добавлением подключаемого модуля sass к существующему коду.В настоящее время мы используем плагин для машинописи и CSS.

const path = require('path')
const withTypescript = require('@zeit/next-typescript')
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass');
const configuration = require('./config/configuration.json')

module.exports = withTypescript(
  withCSS({
      webpack(config) {
        if (process.env.ANALYZE) {
          config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: 'server',
            analyzerPort: 8888,
            openAnalyzer: true,
          }))
        }
        return config
      },
      cssModules: true,
      serverRuntimeConfig: { 
        // Will only be available on the server side
      },
      publicRuntimeConfig: { 
        // Will be available on both server and client
      }
    })
  )

Я хотел добавить плагин sass без возможности работать над проектом, пока я реализую sass.

1 Ответ

0 голосов
/ 17 февраля 2019

Вот как можно добавить больше плагинов.

В вашей функции webpack(config) { /* ... */ } вы можете продолжать добавлять больше плагинов в config.plugins.

Например, здесь я добавил WebpackBar плагин, который профилирует ваш скрипт сборки.

webpack(config) {
    if (process.env.ANALYZE) {
        config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: 'server',
            analyzerPort: 8888,
            openAnalyzer: true,
        }))
    }

    config.plugins.push(new WebpackBar({
        fancy: true,
        profile: true,
        basic: false,
    }));

    // just do as many config.plugins.push() calls as you need

    return config
},
...