From b44734a148cf73b11abe2a33037e2122754cfe5f Mon Sep 17 00:00:00 2001 From: eduardhrachou Date: Tue, 9 Jan 2024 12:33:28 +0300 Subject: [PATCH] build optimization --- gatsby-node.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 75a5d4fbaae..b29f18a9fff 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -397,27 +397,29 @@ const style_lint_options = { lintDirtyModulesOnly: true, } -exports.onCreateWebpackConfig = ({ stage, actions, loaders, getConfig }, { ...options }) => { - const config = getConfig() - if (config.optimization) { - config.optimization.minimizer = [new TerserPlugin()] - } - if (stage === 'build-html' || stage === 'develop-html') { - actions.setWebpackConfig({ - module: { - rules: [ - { - test: /analytics/, - use: loaders.null(), - }, - ], - }, - }) - } +exports.onCreateWebpackConfig = ({ stage, actions, loaders }, { noUglify, ...options }) => { + const isProduction = stage === 'build-html' || stage === 'build-javascript' + actions.setWebpackConfig({ + devtool: false, + performance: { + hints: isProduction ? 'warning' : false, + }, + optimization: { + minimize: isProduction && !noUglify, + minimizer: isProduction && !noUglify ? [new TerserPlugin()] : [], + }, plugins: [new StylelintPlugin({ ...style_lint_options, ...options })], resolve: { modules: [path.resolve(__dirname, 'src'), 'node_modules'], }, + module: { + rules: [ + { + test: /analytics/, + use: loaders.null(), + }, + ], + }, }) }