Skip to content

Commit

Permalink
refactor: CRA exemple without CRACO (#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
neysimoes authored Jun 21, 2022
1 parent e71bb68 commit 9239949
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ This example demos a basic host application loading remote component.

Run `yarn start`. This will build and serve both `host` and `remote` on ports 3001 and 3002 respectively.

- [localhost:3001](http://localhost:3001/) (HOST)
- [localhost:3001](http://localhost:3000/) (HOST)
- [localhost:3002](http://localhost:3002/) (STANDALONE REMOTE)
9 changes: 0 additions & 9 deletions cra/host/craco.config.js

This file was deleted.

8 changes: 2 additions & 6 deletions cra/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react-scripts": "5.0.1"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"start": "node ./scripts/start.js",
"build": "node ./scripts/build.js",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand All @@ -18,10 +18,6 @@
"react-app"
]
},
"devDependencies": {
"@craco/craco": "6.4.3",
"craco-module-federation": "1.1.0"
},
"browserslist": {
"production": [
">0.2%",
Expand Down
3 changes: 3 additions & 0 deletions cra/host/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.NODE_ENV = 'production';
require('./overrides/webpack-config');
require('react-scripts/scripts/build');
16 changes: 16 additions & 0 deletions cra/host/scripts/overrides/webpack-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { ModuleFederationPlugin } = require('webpack').container;

const webpackConfigPath = 'react-scripts/config/webpack.config';
const webpackConfig = require(webpackConfigPath);

const override = (config) => {
config.plugins.push(new ModuleFederationPlugin(require('../../modulefederation.config.js')));

config.output.publicPath = 'auto';

return config;
};

require.cache[require.resolve(webpackConfigPath)].exports = (env) => override(webpackConfig(env));

module.exports = require(webpackConfigPath);
3 changes: 3 additions & 0 deletions cra/host/scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
require('./overrides/webpack-config');
require('react-scripts/scripts/start');
9 changes: 0 additions & 9 deletions cra/remote/craco.config.js

This file was deleted.

8 changes: 2 additions & 6 deletions cra/remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react-scripts": "5.0.1"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"start": "PORT=3002 node ./scripts/start.js",
"build": "node ./scripts/build.js",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand All @@ -18,10 +18,6 @@
"react-app"
]
},
"devDependencies": {
"@craco/craco": "6.4.3",
"craco-module-federation": "1.1.0"
},
"browserslist": {
"production": [
">0.2%",
Expand Down
3 changes: 3 additions & 0 deletions cra/remote/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.NODE_ENV = 'production';
require('./overrides/webpack-config');
require('react-scripts/scripts/build');
16 changes: 16 additions & 0 deletions cra/remote/scripts/overrides/webpack-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { ModuleFederationPlugin } = require('webpack').container;

const webpackConfigPath = 'react-scripts/config/webpack.config';
const webpackConfig = require(webpackConfigPath);

const override = (config) => {
config.plugins.push(new ModuleFederationPlugin(require('../../modulefederation.config.js')));

config.output.publicPath = 'auto';

return config;
};

require.cache[require.resolve(webpackConfigPath)].exports = (env) => override(webpackConfig(env));

module.exports = require(webpackConfigPath);
3 changes: 3 additions & 0 deletions cra/remote/scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
require('./overrides/webpack-config');
require('react-scripts/scripts/start');

0 comments on commit 9239949

Please sign in to comment.