-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
112 lines (93 loc) · 3.87 KB
/
webpack.config.js
File metadata and controls
112 lines (93 loc) · 3.87 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require('path');
const fs = require('fs');
const Encore = require('@symfony/webpack-encore');
const SyliusAdmin = require('@sylius-ui/admin');
const SyliusShop = require('@sylius-ui/shop');
// Admin config
const adminConfig = SyliusAdmin.getBaseWebpackConfig(path.resolve(__dirname));
// Shop config
const shopConfig = SyliusShop.getBaseWebpackConfig(path.resolve(__dirname));
// Shared controllers
const common_controllers = path.resolve(__dirname, './assets/controllers.json');
// App shop config
Encore
.setOutputPath('public/build/app/shop')
.setPublicPath('/build/app/shop')
.copyFiles({
from: './assets/shop/images',
to: 'images/[path][name].[hash:8].[ext]',
pattern: /\.(png|jpe?g|gif|svg|webp)$/
})
.addEntry('app-shop-entry', './assets/shop/entrypoint.js')
.addAliases({
'@vendor': path.resolve(__dirname, 'vendor'),
})
.disableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
// Displays build status system notifications to the user
// .enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader()
// .enableStimulusBridge(path.resolve(__dirname, './assets/shop/controllers.json'))
// remove the following line if you don't want to add automatically controllers provided by plugins
// You then have to copy them to assets/shop/controllers.json
.enableStimulusBridge(mergeControllers(
'shop',
[common_controllers, path.resolve(__dirname, './assets/shop/controllers.json')]
))
;
const appShopConfig = Encore.getWebpackConfig();
appShopConfig.externals = Object.assign({}, appShopConfig.externals, { window: 'window', document: 'document' });
appShopConfig.name = 'app.shop';
Encore.reset();
// App admin config
Encore
.setOutputPath('public/build/app/admin')
.setPublicPath('/build/app/admin')
.copyFiles({
from: './assets/admin/images',
to: 'images/[path][name].[hash:8].[ext]',
pattern: /\.(png|jpe?g|gif|svg|webp)$/
})
.addEntry('app-admin-entry', './assets/admin/entrypoint.js')
.addAliases({
'@vendor': path.resolve(__dirname, 'vendor'),
})
.disableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableSassLoader()
//.enableStimulusBridge(path.resolve(__dirname, './assets/admin/controllers.json'))
// remove the following line if you don't want to add automatically controllers provided by plugins
// You then have to copy them to assets/admin/controllers.json
.enableStimulusBridge(mergeControllers(
'admin',
[common_controllers, path.resolve(__dirname, './assets/admin/controllers.json')]
))
;
const appAdminConfig = Encore.getWebpackConfig();
appAdminConfig.externals = Object.assign({}, appAdminConfig.externals, { window: 'window', document: 'document' });
appAdminConfig.name = 'app.admin';
module.exports = [shopConfig, adminConfig, appShopConfig, appAdminConfig];
/**
* Merge controllers.json from multiple files into one and store in cache
* Used to merge both controllers.json fed by packages and the one from the app
*/
function mergeControllers(name, filePaths, cacheDir = 'var/cache/webpack') {
const merged = filePaths.reduce(
(acc, filePath) => {
const json = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
acc.controllers = { ...acc.controllers, ...json.controllers };
acc.entrypoints = { ...acc.entrypoints, ...json.entrypoints };
return acc;
},
{ controllers: {}, entrypoints: {} }
);
const tmpDir = path.resolve(__dirname, cacheDir);
if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true });
const outFile = path.join(tmpDir, `controllers.merged.${name}.json`);
fs.writeFileSync(outFile, JSON.stringify(merged, null, 2), 'utf-8');
return outFile;
}