Skip to content

Commit cc30762

Browse files
committed
bug #1247 bug: accept use with addPlugin only (gimler)
This PR was merged into the main branch. Discussion ---------- bug: accept use with addPlugin only i have a multi config setup. In one of my configs i only call `addPlugin()`. ```js const path = require('node:path'); const fileName = process.env.COPY_FILE_NAME || false; let copyConfig = {}; if (fileName) { copyConfig = { from: `${fileName}`, to: `${path.dirname(path.relative(path.resolve(__dirname, 'picture'), fileName))}/[name].[contenthash:8][ext]`, } } else { copyConfig = { from: './picture', to: '[path][name].[contenthash:8][ext]' } Encore.cleanupOutputBeforeBuild() }; const CopyPlugin = require('copy-webpack-plugin'); Encore ... .addPlugin( new CopyPlugin({ patterns: [copyConfig], }) ) ... ``` this config only copy files optional only a specific ;) Actually only use `addPlugin()` is not supported. I change the code and add test for the scenario. releated #1140 Commits ------- 1bfd797 bug: accept use with addPlugin only
2 parents a3f6855 + 1bfd797 commit cc30762

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/config/validator.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class Validator {
4343
if (this.webpackConfig.entries.size === 0
4444
&& this.webpackConfig.styleEntries.size === 0
4545
&& this.webpackConfig.copyFilesConfigs.length === 0
46+
&& this.webpackConfig.plugins.length === 0
4647
) {
47-
throw new Error('No entries found! You must call addEntry() or addEntries() or addStyleEntry() or copyFiles() at least once - otherwise... there is nothing to webpack!');
48+
throw new Error('No entries found! You must call addEntry() or addEntries() or addStyleEntry() or copyFiles() or addPlugin() at least once - otherwise... there is nothing to webpack!');
4849
}
4950
}
5051

test/config/validator.js

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function createConfig() {
2424
}
2525

2626
describe('The validator function', () => {
27+
function CustomPlugin1() {}
28+
2729
it('throws an error if there are no entries', () => {
2830
const config = createConfig();
2931
config.publicPath = '/';
@@ -47,6 +49,17 @@ describe('The validator function', () => {
4749
expect(Object.keys(config.copyFilesConfigs).length).to.equal(1);
4850
});
4951

52+
it('should accept use with addPlugin() only', () => {
53+
const config = createConfig();
54+
config.setOutputPath('/tmp');
55+
config.setPublicPath('/tmp');
56+
config.addPlugin(new CustomPlugin1());
57+
58+
expect(() => {
59+
validator(config);
60+
}).not.throw();
61+
});
62+
5063
it('throws an error if there is no output path', () => {
5164
const config = createConfig();
5265
config.publicPath = '/';

0 commit comments

Comments
 (0)