mirror of https://github.com/status-im/metro.git
Don’t use spaces when amending module wrapper
Summary: since we use the same module wrapper amendment function for dev and prod builds, and code is already minified at this point, we minify ourselves by leaving out space. Reviewed By: cpojer Differential Revision: D4265967 fbshipit-source-id: 719a3bbfbc02c9af1bb3fa08317b2f1b92c141a5
This commit is contained in:
parent
b3ad054424
commit
d80f231ef8
|
@ -40,13 +40,13 @@ describe('`addModuleIdsToModuleWrapper`:', () => {
|
|||
.withArgs(match({path: dependencies[1].path})).returns(6);
|
||||
|
||||
expect(addModuleIdsToModuleWrapper(module, idForPath))
|
||||
.toEqual('__d(function(){}, 12, [345, 6]);');
|
||||
.toEqual('__d(function(){},12,[345,6]);');
|
||||
});
|
||||
|
||||
it('omits the array of dependency IDs if it is empty', () => {
|
||||
const module = createModule();
|
||||
expect(addModuleIdsToModuleWrapper(module, () => 98))
|
||||
.toEqual(`__d(function(){}, ${98});`);
|
||||
.toEqual(`__d(function(){},${98});`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -26,11 +26,19 @@ exports.addModuleIdsToModuleWrapper = (
|
|||
const {dependencies, file} = module;
|
||||
const {code} = file;
|
||||
const index = code.lastIndexOf(')');
|
||||
|
||||
// calling `idForPath` on the module itself first gives us a lower module id
|
||||
// for the file itself than for its dependencies. That reflects their order
|
||||
// in the bundle.
|
||||
const fileId = idForPath(file);
|
||||
|
||||
// This code runs for both development and production builds, after
|
||||
// minification. That's why we leave out all spaces.
|
||||
const depencyIds =
|
||||
dependencies.length ? `, [${dependencies.map(idForPath).join(', ')}]` : '';
|
||||
dependencies.length ? `,[${dependencies.map(idForPath).join(',')}]` : '';
|
||||
return (
|
||||
code.slice(0, index) +
|
||||
`, ${idForPath(file)}` +
|
||||
`,${fileId}` +
|
||||
depencyIds +
|
||||
code.slice(index)
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue