-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfederate.js
More file actions
61 lines (53 loc) · 1.92 KB
/
federate.js
File metadata and controls
61 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const importLazy = require('import-lazy')(require);
const { contextMiddleware } = importLazy('../cli/context-middleware');
const StripesCore = importLazy('../cli/stripes-core');
const StripesPlatform = importLazy('../platform/stripes-platform');
const { stripesConfigFile } = importLazy('./common-options');
let _stripesPlatform;
let _stripesCore;
// stripesPlatform and stripesCore overrides primarily used as injection for unit tests
function stripesOverrides(stripesPlatform, stripesCore) {
_stripesPlatform = stripesPlatform;
_stripesCore = stripesCore;
}
function federateCommand(argv) {
const context = argv.context;
// Default federate command to production env
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}
const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv);
const webpackOverrides = [];
if (argv.analyze) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line
webpackOverrides.push((config) => {
config.plugins.push(new BundleAnalyzerPlugin());
return config;
});
}
console.info('Federate module...');
const stripes = _stripesCore || new StripesCore(context, platform.aliases);
stripes.api.federate(Object.assign({}, argv, { webpackOverrides }));
}
module.exports = {
command: 'federate',
describe: 'federate single module',
builder: (yargs) => {
yargs
.middleware([
contextMiddleware(),
])
.positional('configFile', stripesConfigFile.configFile)
.option('analyze', {
describe: 'Run the Webpack Bundle Analyzer after build (launches in browser)',
type: 'boolean',
})
.option('port', {
describe: 'A port which will be used for the remote federated module',
type: 'number',
})
.example('$0 federate', 'federate a module');
},
handler: federateCommand,
stripesOverrides,
};