Skip to content

Commit 7c2210d

Browse files
authored
IBX-10173: Extract webpack files from root dir (#1)
1 parent 477701c commit 7c2210d

File tree

8 files changed

+158
-108
lines changed

8 files changed

+158
-108
lines changed

.github/workflows/backend-ci.yaml

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/frontend-ci.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
yarn.lock

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1-
Ibexa DXP \<Package name\>
2-
====================
1+
# Ibexa DXP Frontend Config
2+
3+
## Usage
4+
This JS package should be used only with Ibexa DXP from root directory - for proper functioning it requires specific files structure provided by Ibexa DXP.
5+
6+
## Webpack
7+
### Ibexa config
8+
Usage:
9+
```
10+
const Encore = require('@symfony/webpack-encore');
11+
const getIbexaConfig = require('@ibexa/frontend-config/webpack-config');
12+
13+
const bundles = require('./var/encore/ibexa.config.js');
14+
const managers = require('./var/encore/ibexa.config.manager.js');
15+
const setups = require('./var/encore/ibexa.config.setup.js');
16+
17+
const ibexaConfig = getIbexaConfig(Encore, { bundles, managers, setups }, modifyEncoreConfig);
18+
```
19+
Optional arguments:
20+
21+
`modifyEncoreConfig(Encore)`: function that takes Encore object and allows modifying its config, executes just before `Encore.getWebpackConfig()`;
22+
23+
### Custom config
24+
Usage:
25+
```
26+
const Encore = require('@symfony/webpack-encore');
27+
const getCustomConfigs = require('@ibexa/frontend-config/webpack-config/custom');
28+
29+
const customConfigsPaths = require('./var/encore/ibexa.webpack.custom.config.js');
30+
31+
const customConfigs = getCustomConfigs(Encore, customConfigsPaths);
32+
```
333

434
## COPYRIGHT
535
Copyright (C) 1999-2025 Ibexa AS (formerly eZ Systems AS). All rights reserved.

ibexa.webpack.config.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const path = require('path');
2+
3+
const ibexaConfigManager = require('./ibexa.webpack.config.manager.js');
4+
5+
module.exports = (Encore, { bundles, managers, setups }, modifyEncoreConfig) => {
6+
process.env.NODE_ENV ??= Encore.isProduction() ? 'production' : 'development';
7+
8+
Encore.setOutputPath('public/assets/ibexa/build')
9+
.setPublicPath('/assets/ibexa/build')
10+
.addExternals({
11+
react: 'React',
12+
'react-dom': 'ReactDOM',
13+
moment: 'moment',
14+
'popper.js': 'Popper',
15+
alloyeditor: 'AlloyEditor',
16+
'prop-types': 'PropTypes',
17+
})
18+
.enableSassLoader()
19+
.enableTypeScriptLoader((tsConfig) => {
20+
tsConfig.configFile = path.resolve('tsconfig.json');
21+
})
22+
.enableForkedTypeScriptTypesChecking((tsConfig) => {
23+
tsConfig.async = true;
24+
})
25+
.enableReactPreset()
26+
.enableSingleRuntimeChunk();
27+
28+
setups.forEach((configSetupPath) => {
29+
const setupConfig = require(path.resolve(configSetupPath));
30+
31+
setupConfig(Encore);
32+
});
33+
34+
bundles.forEach((configPath) => {
35+
const addEntries = require(path.resolve(configPath));
36+
37+
addEntries(Encore);
38+
});
39+
40+
if (typeof modifyEncoreConfig === 'function') {
41+
modifyEncoreConfig(Encore);
42+
}
43+
44+
const ibexaConfig = Encore.getWebpackConfig();
45+
46+
ibexaConfig.name = 'ibexa';
47+
48+
ibexaConfig.module.rules[4].oneOf[1].use[1].options.url = false;
49+
ibexaConfig.module.rules[1].oneOf[1].use[1].options.url = false;
50+
51+
managers.forEach((configManagerPath) => {
52+
const configManager = require(path.resolve(configManagerPath));
53+
54+
configManager(ibexaConfig, ibexaConfigManager);
55+
});
56+
57+
Encore.reset();
58+
59+
return ibexaConfig;
60+
};

ibexa.webpack.config.manager.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const fs = require('fs');
2+
3+
const findItems = (ibexaConfig, entryName) => {
4+
const items = ibexaConfig.entry[entryName];
5+
6+
if (!items) {
7+
throw new Error(`Couldn't find entry with name: "${entryName}". Please check if there is a typo in the name.`);
8+
}
9+
10+
return items;
11+
};
12+
const replace = ({ ibexaConfig, entryName, itemToReplace, newItem }) => {
13+
const items = findItems(ibexaConfig, entryName);
14+
const indexToReplace = items.indexOf(fs.realpathSync(itemToReplace));
15+
16+
if (indexToReplace < 0) {
17+
throw new Error(`Couldn't find item "${itemToReplace}" in entry "${entryName}". Please check if there is a typo in the name.`);
18+
}
19+
20+
items[indexToReplace] = newItem;
21+
};
22+
const remove = ({ ibexaConfig, entryName, itemsToRemove }) => {
23+
const items = findItems(ibexaConfig, entryName);
24+
const realPathItemsToRemove = itemsToRemove.map((item) => fs.realpathSync(item));
25+
26+
ibexaConfig.entry[entryName] = items.filter((item) => !realPathItemsToRemove.includes(item));
27+
};
28+
const add = ({ ibexaConfig, entryName, newItems }) => {
29+
const items = findItems(ibexaConfig, entryName);
30+
31+
ibexaConfig.entry[entryName] = [...items, ...newItems];
32+
};
33+
34+
module.exports = {
35+
replace,
36+
remove,
37+
add
38+
};

ibexa.webpack.custom.configs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path');
2+
3+
module.exports = (Encore, customConfigs) => customConfigs.reduce((configs, customConfigPath) => {
4+
let customConfig = require(path.resolve(customConfigPath));
5+
6+
if (typeof customConfig === 'function') {
7+
customConfig = customConfig(Encore);
8+
}
9+
10+
if (!Array.isArray(customConfig)) {
11+
customConfig = [customConfig];
12+
}
13+
14+
return [ ...configs, ...customConfig ];
15+
}, []);

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@ibexa/frontend-config",
3+
"packageManager": "yarn@1.22.22",
4+
"version": "5.0.0-beta1",
5+
"repository": "git@github.com:ibexa/frontend-config.git",
6+
"exports": {
7+
"./webpack-config": "./ibexa.webpack.config.js",
8+
"./webpack-config/manager": "./ibexa.webpack.config.manager.js",
9+
"./webpack-config/custom": "./ibexa.webpack.custom.configs.js"
10+
}
11+
}

0 commit comments

Comments
 (0)