Skip to content

Webpack to bundle react apps together on progressively decoupled projects

Notifications You must be signed in to change notification settings

Bixal/bixal-webpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set up your decoupled environment:

  1. Create apps using create-react-app or place in /apps.

  2. Merge the package.json files to ./package.json and delete them from the individual apps.

  3. Run: 'npm install'

  4. Create a block for your app in: web/modules/custom/YOURMODULE/src/Plugin/Block/.

  5. Run: 'npm run build'

  6. Add app to YOURMODULE.libraries.yml.

your-app:
  version: 1.x
  css:
      theme:
        tools/build/static/css/your-app.min.css: {}
  js:
    tools/build/static/js/your-app.min.js: {}
  1. Create a Block for your app.
?php

namespace Drupal\YOURMODULE\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'YourAppBlock' block.
 *
 * @Block(
 *  id = "your_app_block",
 *  admin_label = @Translation("Your app block"),
 * )
 */
class YourAppBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    $build = [];
    $build['your_app_block']['#attached']['library'][] = 'YOURMODULE/your-app';
    $build['your_app_block']['#markup'] = '<div id="your-app"></div>';
    $build['#cache'] = ['max-age' => 0];

    return $build;
  }

}
  1. Make sure the div id matches the id defined in your-app/src/index.js
ReactDOM.render(<App />, document.getElementById('your-app'));

About

Webpack to bundle react apps together on progressively decoupled projects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •