diff --git a/packages/create-gasket-app/lib/scaffold/config-builder.js b/packages/create-gasket-app/lib/scaffold/config-builder.js index 49d1036e7..264d9f44f 100644 --- a/packages/create-gasket-app/lib/scaffold/config-builder.js +++ b/packages/create-gasket-app/lib/scaffold/config-builder.js @@ -256,7 +256,7 @@ export class ConfigBuilder { * }, */ addEnvironment(key, value) { - this.add(`environments`, { + this.add('environments', { [key]: value }); } diff --git a/packages/gasket-plugin-analyze/lib/create.js b/packages/gasket-plugin-analyze/lib/create.js index d8ed846b3..9fa87a6b2 100644 --- a/packages/gasket-plugin-analyze/lib/create.js +++ b/packages/gasket-plugin-analyze/lib/create.js @@ -6,13 +6,17 @@ const { name, version } = require('../package.json'); * @type {import('@gasket/core').HookHandler<'create'>} */ module.exports = function create(gasket, { pkg, gasketConfig }) { - gasketConfig.addPlugin('pluginAnalyze', name); + gasketConfig.addEnvironment('local.analyze', { + dynamicPlugins: [ + '@gasket/plugin-analyze' + ] + }); pkg.add('devDependencies', { [name]: `^${version}` }); pkg.add('scripts', { - analyze: 'ANALYZE=true next build' + analyze: 'GASKET_ENV=local.analyze ANALYZE=1 next build' }); }; diff --git a/packages/gasket-plugin-analyze/lib/webpack-config.js b/packages/gasket-plugin-analyze/lib/webpack-config.js index 81af96910..3fdeef9b8 100644 --- a/packages/gasket-plugin-analyze/lib/webpack-config.js +++ b/packages/gasket-plugin-analyze/lib/webpack-config.js @@ -9,8 +9,12 @@ module.exports = function webpackConfigHook(gasket, webpackConfig, context) { config: { bundleAnalyzerConfig: userConfig = {} } } = gasket; - // Only add the analyzer plugin if ANALYZE flag is true if (process.env.ANALYZE === 'true') { + console.warn("Deprecation Warning: Using 'true' for the ANALYZE environment variable is deprecated. Please use '1' instead."); + } + + // Only add the analyzer plugin if ANALYZE flag is true + if (process.env.ANALYZE === 'true' || process.env.ANALYZE === '1') { const merge = require('deepmerge'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const defaultConfig = require('./default-config'); diff --git a/packages/gasket-plugin-analyze/test/create.spec.js b/packages/gasket-plugin-analyze/test/create.spec.js index ed0a27923..437edb07c 100644 --- a/packages/gasket-plugin-analyze/test/create.spec.js +++ b/packages/gasket-plugin-analyze/test/create.spec.js @@ -5,14 +5,18 @@ describe('create', () => { it('adds the analyze script and adds the plugin', async () => { const add = jest.fn(); - const addPlugin = jest.fn(); - await create({}, { pkg: { add }, gasketConfig: { addPlugin } }); + const addEnvironment = jest.fn(); + await create({}, { pkg: { add }, gasketConfig: { addEnvironment } }); expect(add.mock.calls[0]).toEqual(['devDependencies', { [name]: `^${version}` }]); expect(add.mock.calls[1]).toEqual(['scripts', { - analyze: 'ANALYZE=true next build' + analyze: 'GASKET_ENV=local.analyze ANALYZE=1 next build' }]); - expect(addPlugin.mock.calls[0]).toEqual(['pluginAnalyze', name]); + expect(addEnvironment).toHaveBeenCalledWith('local.analyze', { + dynamicPlugins: [ + '@gasket/plugin-analyze' + ] + }); }); });