Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
build optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard-deriv committed Jan 9, 2024
1 parent 6d6638a commit b44734a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
],
},
})
}

0 comments on commit b44734a

Please sign in to comment.