forked from spryker-shop/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassets-configurator.js
52 lines (46 loc) · 1.31 KB
/
assets-configurator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const getCopyConfig = appSettings =>
Object.values(appSettings.paths.assets).reduce((copyConfig, assetsPath) => {
if (fs.existsSync(assetsPath)) {
copyConfig.push({
from: assetsPath,
to: '.',
ignore: ['*.gitkeep'],
});
}
return copyConfig;
},[]);
const getCopyStaticConfig = appSettings => {
const staticAssetsPath = appSettings.paths.assets.staticAssets;
if (fs.existsSync(staticAssetsPath)) {
return [{
from: staticAssetsPath,
to: appSettings.paths.publicStatic,
}];
}
return [];
};
const getAssetsConfig = appSettings => [
new CleanWebpackPlugin(
[
appSettings.paths.public,
appSettings.paths.publicStatic,
],
{
root: appSettings.context,
verbose: true,
beforeEmit: true,
}
),
new CopyWebpackPlugin(getCopyConfig(appSettings), {
context: appSettings.context,
}),
new CopyWebpackPlugin(getCopyStaticConfig(appSettings), {
context: appSettings.context,
}),
];
module.exports = {
getAssetsConfig
};