如何在 next.config.js 中添加两个以上的插件
How to add more than two plugins in a next.config.js
我想在我们公司的项目中实施 sass 和 BEM 方法,但是,我在将 sass 插件添加到现有代码时遇到了一些麻烦。目前,我们正在使用 typescript 和 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 时仍然无法处理该项目。
这是添加更多插件的方法。
在您的 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
},
我想在我们公司的项目中实施 sass 和 BEM 方法,但是,我在将 sass 插件添加到现有代码时遇到了一些麻烦。目前,我们正在使用 typescript 和 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 时仍然无法处理该项目。
这是添加更多插件的方法。
在您的 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
},