Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CRA exemple without CRACO #2028

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');