diff --git a/code_samples/ai_actions/webpack.config.js b/code_samples/ai_actions/webpack.config.js index 9b28fa5dda9..882fbea9668 100644 --- a/code_samples/ai_actions/webpack.config.js +++ b/code_samples/ai_actions/webpack.config.js @@ -1,4 +1,6 @@ -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); ibexaConfigManager.add({ ibexaConfig, @@ -7,3 +9,5 @@ ibexaConfigManager.add({ path.resolve(__dirname, './assets/js/addAudioModule.js') ], }); + +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; diff --git a/code_samples/back_office/image_editor/config/webpack.config.js b/code_samples/back_office/image_editor/config/webpack.config.js index ef649502954..760fc197133 100644 --- a/code_samples/back_office/image_editor/config/webpack.config.js +++ b/code_samples/back_office/image_editor/config/webpack.config.js @@ -1,34 +1,30 @@ -const Encore = require('@symfony/webpack-encore'); +const fs = require('fs'); const path = require('path'); -const getIbexaConfig = require('./ibexa.webpack.config.js'); -const ibexaConfig = getIbexaConfig(Encore); -const customConfigs = require('./ibexa.webpack.custom.configs.js'); -const { isReactBlockPathCreated } = require('./ibexa.webpack.config.react.blocks.js'); -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const Encore = require('@symfony/webpack-encore'); +const getWebpackConfigs = require('@ibexa/frontend-config/webpack-config/get-configs'); +const customConfigsPaths = require('./var/encore/ibexa.webpack.custom.config.js'); + +const customConfigs = getWebpackConfigs(Encore, customConfigsPaths); +const isReactBlockPathCreated = fs.existsSync('./assets/page-builder/react/blocks'); Encore.reset(); Encore .setOutputPath('public/build/') .setPublicPath('/build') - .enableStimulusBridge('./assets/controllers.json') .enableSassLoader() - .enableReactPreset() + .enableReactPreset((options) => { + options.runtime = 'classic'; + }) .enableSingleRuntimeChunk() .copyFiles({ from: './assets/images', to: 'images/[path][name].[ext]', - pattern: /\.(png|svg)$/ - }) - .configureBabel((config) => { - config.plugins.push('@babel/plugin-proposal-class-properties'); + pattern: /\.(png|svg)$/, }) - - // enables @babel/preset-env polyfills .configureBabelPresetEnv((config) => { config.useBuiltIns = 'usage'; config.corejs = 3; - }) -; + }); // Welcome page stylesheets Encore.addEntry('welcome-page-css', [ @@ -47,18 +43,23 @@ if (isReactBlockPathCreated) { Encore.addEntry('app', './assets/app.js'); -// Image Editor Dot Action +const projectConfig = Encore.getWebpackConfig(); + +projectConfig.name = 'app'; + +module.exports = [...customConfigs, projectConfig]; + +/* Get ibexaConfig and ibexaConfigManager */ +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); + +/* Add dot action to Admin UI layout JS */ ibexaConfigManager.add({ ibexaConfig, entryName: 'ibexa-admin-ui-layout-js', newItems: [ path.resolve(__dirname, './assets/random_dot/random-dot.js'), ], }); -const projectConfig = Encore.getWebpackConfig(); - -projectConfig.name = 'app'; - +/* Export updated ibexaConfig and previous modules */ module.exports = [ibexaConfig, ...customConfigs, projectConfig]; - -// uncomment this line if you've commented-out the above lines -// module.exports = [ eZConfig, ibexaConfig, ...customConfigs ]; diff --git a/code_samples/back_office/search/append_to_webpack.config.js b/code_samples/back_office/search/append_to_webpack.config.js index 5146bc2a0e1..af59388a829 100644 --- a/code_samples/back_office/search/append_to_webpack.config.js +++ b/code_samples/back_office/search/append_to_webpack.config.js @@ -1,7 +1,11 @@ -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); ibexaConfigManager.add({ ibexaConfig, entryName: 'ibexa-admin-ui-layout-js', newItems: [path.resolve(__dirname, './assets/js/admin.search.autocomplete.product.js')], }); + +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; diff --git a/code_samples/forms/custom_form_attribute/webpack.config.js b/code_samples/forms/custom_form_attribute/webpack.config.js index ae74f9e82aa..bc93fbbff82 100644 --- a/code_samples/forms/custom_form_attribute/webpack.config.js +++ b/code_samples/forms/custom_form_attribute/webpack.config.js @@ -1,33 +1,30 @@ -const Encore = require('@symfony/webpack-encore'); +const fs = require('fs'); const path = require('path'); -const getIbexaConfig = require('./ibexa.webpack.config.js'); -const ibexaConfig = getIbexaConfig(Encore); -const customConfigs = require('./ibexa.webpack.custom.configs.js'); -const { isReactBlockPathCreated } = require('./ibexa.webpack.config.react.blocks.js'); +const Encore = require('@symfony/webpack-encore'); +const getWebpackConfigs = require('@ibexa/frontend-config/webpack-config/get-configs'); +const customConfigsPaths = require('./var/encore/ibexa.webpack.custom.config.js'); + +const customConfigs = getWebpackConfigs(Encore, customConfigsPaths); +const isReactBlockPathCreated = fs.existsSync('./assets/page-builder/react/blocks'); Encore.reset(); Encore .setOutputPath('public/build/') .setPublicPath('/build') - .enableStimulusBridge('./assets/controllers.json') .enableSassLoader() - .enableReactPreset() + .enableReactPreset((options) => { + options.runtime = 'classic'; + }) .enableSingleRuntimeChunk() .copyFiles({ from: './assets/images', to: 'images/[path][name].[ext]', - pattern: /\.(png|svg)$/ + pattern: /\.(png|svg)$/, }) - .configureBabel((config) => { - config.plugins.push('@babel/plugin-proposal-class-properties'); - }) - - // enables @babel/preset-env polyfills .configureBabelPresetEnv((config) => { config.useBuiltIns = 'usage'; config.corejs = 3; - }) -; + }); // Welcome page stylesheets Encore.addEntry('welcome-page-css', [ @@ -52,7 +49,4 @@ const projectConfig = Encore.getWebpackConfig(); projectConfig.name = 'app'; -module.exports = [ibexaConfig, ...customConfigs, projectConfig]; - -// uncomment this line if you've commented-out the above lines -// module.exports = [ eZConfig, ibexaConfig, ...customConfigs ]; +module.exports = [...customConfigs, projectConfig]; diff --git a/docs/administration/back_office/back_office_elements/importing_assets_from_bundle.md b/docs/administration/back_office/back_office_elements/importing_assets_from_bundle.md index 992049a038a..55c0d916724 100644 --- a/docs/administration/back_office/back_office_elements/importing_assets_from_bundle.md +++ b/docs/administration/back_office/back_office_elements/importing_assets_from_bundle.md @@ -14,8 +14,8 @@ To import assets from a bundle, configure them in an `ibexa.config.js` file that const path = require('path'); module.exports = (Encore) => { - Encore.addEntry('', [ - path.resolve(__dirname, ''), + Encore.addEntry('', [ + path.resolve(__dirname, ''), ]); }; ``` @@ -40,35 +40,35 @@ To edit existing configuration entries, either in the bundle's `Resources/encore const path = require('path'); module.exports = (ibexaConfig, ibexaConfigManager) => { - ibexaConfigManager.replace({ - ibexaConfig, - entryName: '', - itemToReplace: path.resolve(__dirname, ''), - newItem: path.resolve(__dirname, ''), - }); - ibexaConfigManager.remove({ - ibexaConfig, - entryName: '', - itemsToRemove: [ - path.resolve(__dirname, ''), - path.resolve(__dirname, ''), - ], - }); - ibexaConfigManager.add({ - ibexaConfig, - entryName: '', - newItems: [ - path.resolve(__dirname, ''), - path.resolve(__dirname, ''), - ], - }); + ibexaConfigManager.replace({ + ibexaConfig, + entryName: '', + itemToReplace: path.resolve(__dirname, ''), + newItem: path.resolve(__dirname, ''), + }); + ibexaConfigManager.remove({ + ibexaConfig, + entryName: '', + itemsToRemove: [ + path.resolve(__dirname, ''), + path.resolve(__dirname, ''), + ], + }); + ibexaConfigManager.add({ + ibexaConfig, + entryName: '', + newItems: [ + path.resolve(__dirname, ''), + path.resolve(__dirname, ''), + ], + }); }; ``` !!! tip - If you don't know what `entryName` to use, you can use the browser's developer tools to check what files are loaded on the given page. - Then, use the file name as `entryName`. + If you don't know what `entryName` to use, you can use the browser's developer tools to check what files are loaded on the given page. + Then, use the file name as `entryName`. !!! tip @@ -79,20 +79,20 @@ module.exports = (ibexaConfig, ibexaConfigManager) => { To add a new configuration under your own namespace and with its own dependencies, create an `ibexa.webpack.custom.config.js` file that you create either in the bundle's `Resources/encore/` folder, or in the `encore` folder in the root directory of your project, for example: ``` js - const Encore = require('@symfony/webpack-encore'); + const Encore = require('@symfony/webpack-encore'); - Encore.setOutputPath('') - .setPublicPath('') - .addExternals('') - // ... - .addEntry('', ['']); + Encore.setOutputPath('') + .setPublicPath('') + .addExternals('') + // ... + .addEntry('', ['']); - const customConfig = Encore.getWebpackConfig(); + const customConfig = Encore.getWebpackConfig(); - customConfig.name = 'customConfigName'; + customConfig.name = 'customConfigName'; - // Config or array of configs: [customConfig1, customConfig2]; - module.exports = customConfig; + // Config or array of configs: [customConfig1, customConfig2]; + module.exports = customConfig; ``` !!! tip @@ -103,14 +103,16 @@ To add a new configuration under your own namespace and with its own dependencie ## Configuration from main project files -If you prefer to include the asset configuration in the main project files, add it in [`webpack.config.js`](https://github.com/ibexa/recipes/blob/master/ibexa/oss/4.6/encore/webpack.config.js#L26). +If you prefer to include the asset configuration in the main project files, add it in [`webpack.config.js`](https://github.com/ibexa/recipes/blob/master/ibexa/oss/5.0/encore/webpack.config.js#L26). To overwrite the built-in assets, use the following configuration to replace, remove, or add asset files in `webpack.config.js`: ``` js -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); -//... +//… ibexaConfigManager.replace({ ibexaConfig, @@ -136,4 +138,9 @@ ibexaConfigManager.add({ path.resolve(__dirname, ''), ], }); + +//… + +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; + ``` diff --git a/docs/administration/back_office/browser/add_browser_tab.md b/docs/administration/back_office/browser/add_browser_tab.md index 951636768d9..649bb414114 100644 --- a/docs/administration/back_office/browser/add_browser_tab.md +++ b/docs/administration/back_office/browser/add_browser_tab.md @@ -16,7 +16,7 @@ Follow the instructions below to create and add a new tab called **Images** whic First, in `assets/js/image-tab/`, add an `image.tab.module.js` file. ``` js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js', 0, 14) =]] +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js', 1, 14) =]] ``` Next, add the tab to the configuration in the same file. @@ -29,25 +29,27 @@ Each tab definition is an object containing the following properties: |label|string|Label text, for example, `Images`.| |icon|string|Path to the icon, for example, `/bundles/ibexaadminuiassets/vendors/ids-assets/dist/img/all-icons.svg#info-square`.| -```js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js', 14, 29) =]] +``` js +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js', 15, 28) =]] ``` The module governs the creation of the new tab.
Complete image.tab.module.js code -```js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js') =]] +``` js +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/image.tab.module.js') =]] ```
## Add tab to webpack config -In `webpack.config.js`, add the following declaration: +In `webpack.config.js`, add the following declarations: ```js -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); ``` Next, provide configuration for the new module: @@ -60,6 +62,12 @@ ibexaConfigManager.add({ }); ``` +Finally, export the module back: + +```js +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; +``` + ## Provide ReactJS files Next, you need to provide a set of files used to render the module: @@ -72,24 +80,24 @@ Next, you need to provide a set of files used to render the module: Create a service for fetching the images by adding `images.service.js` to `assets/js/image-tab/services/`: -```js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/services/images.service.js') =]] +``` js +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/services/images.service.js') =]] ``` ### `images.list.js` Next, create an image list by adding an `images.list.js` to `assets/js/image-tab/components/`: -```js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/components/images.list.js') =]] +``` js +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/components/images.list.js') =]] ``` ### `image.js` Finally, create an image view by adding an `image.js` to `assets/js/image-tab/components/`: -```js -[[= include_file('code_samples/back_office/udw/assets/js/image-tab/components/image.js') =]] +``` js +[[= include_code('code_samples/back_office/udw/assets/js/image-tab/components/image.js') =]] ``` ## Add styles @@ -98,14 +106,14 @@ Ensure that the new tab is styled by adding the following files to `assets/css/` ### `images.list.css` -```css -[[= include_file('code_samples/back_office/udw/assets/css/image.list.css') =]] +``` css +[[= include_code('code_samples/back_office/udw/assets/css/image.list.css') =]] ``` ### `image.css` -```css -[[= include_file('code_samples/back_office/udw/assets/css/image.css') =]] +``` css +[[= include_code('code_samples/back_office/udw/assets/css/image.css') =]] ``` ### Add CSS to webpack diff --git a/docs/administration/back_office/customize_search_suggestion.md b/docs/administration/back_office/customize_search_suggestion.md index dc185ac40b6..435008df8c5 100644 --- a/docs/administration/back_office/customize_search_suggestion.md +++ b/docs/administration/back_office/customize_search_suggestion.md @@ -120,7 +120,7 @@ At the end of `webpack.config.js`, add it by using `ibexaConfigManager`: ``` javascript //… -[[= include_file('code_samples/back_office/search/append_to_webpack.config.js') =]] +[[= include_code('code_samples/back_office/search/append_to_webpack.config.js') =]] ``` The renderer, `renderItem` function from `admin.search.autocomplete.product.js`, loads an HTML template from a wrapping DOM node [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset). diff --git a/docs/administration/back_office/subitems_list.md b/docs/administration/back_office/subitems_list.md index 026ab74056b..d78353c66fb 100644 --- a/docs/administration/back_office/subitems_list.md +++ b/docs/administration/back_office/subitems_list.md @@ -54,9 +54,11 @@ And include it into the back office using Webpack Encore, together with your cus See [configuring assets from main project files](importing_assets_from_bundle.md#configuration-from-main-project-files) to learn more about this mechanism. ``` js -const ibexaConfigManager = require('./ibexa.webpack.config.manager.js'); +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); -//... +//… ibexaConfigManager.add({ ibexaConfig, @@ -73,6 +75,8 @@ ibexaConfigManager.add({ path.resolve(__dirname, './assets/scss/timeline.view.scss'), ], }); + +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; ``` Complete the task by running `composer run post-install-cmd`. diff --git a/docs/ai/ai_actions/extend_ai_actions.md b/docs/ai/ai_actions/extend_ai_actions.md index b64718fe835..47ba8701c90 100644 --- a/docs/ai/ai_actions/extend_ai_actions.md +++ b/docs/ai/ai_actions/extend_ai_actions.md @@ -366,7 +366,7 @@ And include it into the back office using Webpack Encore. See [configuring assets from main project files](importing_assets_from_bundle.md#configuration-from-main-project-files) to learn more about this mechanism. ``` js -[[= include_file('code_samples/ai_actions/webpack.config.js') =]] +[[= include_code('code_samples/ai_actions/webpack.config.js') =]] ``` Your custom Action Type is now fully integrated into the back office UI and can be used by the Editors. diff --git a/docs/content_management/forms/create_form_attribute.md b/docs/content_management/forms/create_form_attribute.md index d1bc9496534..192311ce21c 100644 --- a/docs/content_management/forms/create_form_attribute.md +++ b/docs/content_management/forms/create_form_attribute.md @@ -72,8 +72,8 @@ Provide the required script in a new `assets/js/formbuilder-richtext-checkbox.js Then, paste the highlighted part of the code into the `webpack.config.js` file: -``` js hl_lines="49" -[[= include_file('code_samples/forms/custom_form_attribute/webpack.config.js') =]] +``` js hl_lines="46" +[[= include_code('code_samples/forms/custom_form_attribute/webpack.config.js') =]] ``` Clear the cache and regenerate the assets by running the following commands: diff --git a/docs/content_management/images/extend_image_editor.md b/docs/content_management/images/extend_image_editor.md index ea28359c2e6..095a0ceef2f 100644 --- a/docs/content_management/images/extend_image_editor.md +++ b/docs/content_management/images/extend_image_editor.md @@ -32,11 +32,10 @@ Configure the new Image Editor action under the `ibexa.system..image_edit ## Add entry to the Webpack configuration Once you create and configure the React component, you must add an entry to [the Webpack configuration](3_customize_the_front_page.md#configuring-webpack). -In the root directory of your project, modify the `webpack.config.js` file by adding the following code: +In the root directory of your project, modify the `webpack.config.js` file by appending the following code: -``` js -[[= include_file('code_samples/back_office/image_editor/config/webpack.config.js', 6, 7) =]]//... -[[= include_file('code_samples/back_office/image_editor/config/webpack.config.js', 50, 55) =]] +``` js hl_lines="10" +[[= include_code('code_samples/back_office/image_editor/config/webpack.config.js', 52, 65) =]] ``` At this point you should be able to see a new button in the Image Editor's UI. diff --git a/docs/update_and_migration/from_4.6/update_to_5.0.md b/docs/update_and_migration/from_4.6/update_to_5.0.md index 7d601806881..eb1d78bcf80 100644 --- a/docs/update_and_migration/from_4.6/update_to_5.0.md +++ b/docs/update_and_migration/from_4.6/update_to_5.0.md @@ -1,6 +1,6 @@ --- description: Update your installation to v5.0 from the latest v4.6 version. -month_change: false +month_change: true --- # Update from v4.6 to v5.0 @@ -250,7 +250,7 @@ rm assets/bootstrap.js composer recipes:install symfony/webpack-encore-bundle --reset --force --yes ``` -Compare with your previous version, merge them together and test your customizations if needed. +Compare with your previous version, merge them together, take care of [`webpackconfig.js` usage changee](#webpackconfigjs-usage-update), and test your customizations. #### Apply [[= product_name =]] recipe @@ -536,7 +536,7 @@ In the following example, you can see optimization thanks to the following featu #### Update JavaScript -If you haven't renamed your Webpack file since 3.3, do it now as v5.0 no longer supports the old names. +If you haven't renamed your Webpack file since 3.3, do it now as 5.0 no longer supports the old names. | Old name | New name | |:----------------------------|:-------------------------------| @@ -592,6 +592,26 @@ Run it using the following command: yarn --cwd ./vendor/ibexa/rector/js transform ``` +##### `webpack.config.js` usage update + +To add your customizations back into to the new webpack.config.js, take care of the following changes. + +- Contrary to 4.6, in 5.0, `ibexaConfig` isn't available by default in `webpack.config.js`. You have to require then export it. +- The `./ibexa.webpack.config.manager.js` file at project root doesn't exist anymore, you have to require it through its alias path `@ibexa/frontend-config/webpack-config/manager` to get `ibexaConfigManager`. + +```js hl_lines="1-3 10" +const ibexaConfigManager = require('@ibexa/frontend-config/webpack-config/manager'); +const getIbexaConfig = require('@ibexa/frontend-config/webpack-config/ibexa'); +const ibexaConfig = getIbexaConfig(); + +ibexaConfigManager.add({ + ibexaConfig, + //… +}); + +module.exports = [ibexaConfig, ...customConfigs, projectConfig]; +``` + #### Update field type identifiers Several field type identifiers have changed. @@ -602,7 +622,7 @@ The output as an `alias` column with new identifiers and a `legacy_alias` column ??? note "Field type identifiers renaming map" - | old identifier (`legacy_alias`) | new identifier (`alias`) | + | Old identifier (`legacy_alias`) | New identifier (`alias`) | |:--------------------------------|:--------------------------------| | ibexa_address | ibexa_address | | ezauthor | ibexa_author |