Skip to content

Commit 0ef7ff3

Browse files
mendrewsapegin
authored andcommitted
Fix: A build should't break when assetsDir is an array (styleguidist#1367)
copy-webpack-plugin is not allowed `from` to be as an array. If we still want to use `from` and support array format for assetsDir, then we should pass array of objects `{from: ...}` to the plugin. Closes styleguidist#1320
1 parent f35b307 commit 0ef7ff3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/scripts/__tests__/make-webpack-config.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ it('should set from with assetsDir in CopyWebpackPlugin', () => {
114114
expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets/' }]); //([
115115
});
116116

117+
it('should set array of from with assetsDir array in CopyWebpackPlugin', () => {
118+
makeWebpackConfig({ ...styleguideConfig, assetsDir: ['/assets1/', '/assets2/'] }, 'production');
119+
expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets1/' }, { from: '/assets2/' }]);
120+
});
121+
117122
it('should add CopyWebpackPlugin to plugins in production', () => {
118123
makeWebpackConfig({ ...styleguideConfig }, 'production');
119124
expect(CopyWebpackPlugin).toHaveBeenCalledWith([]);

src/scripts/make-webpack-config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const castArray = require('lodash/castArray');
23
const webpack = require('webpack');
34
const TerserPlugin = require('terser-webpack-plugin');
45
const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin');
@@ -92,13 +93,7 @@ module.exports = function(config, env) {
9293
verbose: config.verbose === true,
9394
}),
9495
new CopyWebpackPlugin(
95-
config.assetsDir
96-
? [
97-
{
98-
from: config.assetsDir,
99-
},
100-
]
101-
: []
96+
config.assetsDir ? castArray(config.assetsDir).map(dir => ({ from: dir })) : []
10297
),
10398
],
10499
optimization: {

0 commit comments

Comments
 (0)