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

Importing a file with universal includes all the contents of its sibling directories #197

Open
volkanunsal opened this issue Sep 18, 2019 · 6 comments

Comments

@volkanunsal
Copy link

Hello,

I'm running into an issue in my production builds. This is what I have in my bundle file.

const CompanyEdit = universal(import('comps/Company/Edit'));

The production build of the system includes the contents of __tests__ and __generated__ folders.

	public/__generated__-GetKey.chunk-647967baa76de181db7c.js
	public/__generated__-GetKey.chunk-647967baa76de181db7c.js.map
	public/__generated__-RegenKey.chunk-4f4202d851a015422d6d.js
	public/__generated__-RegenKey.chunk-4f4202d851a015422d6d.js.map
	public/__generated__-updateCompany.chunk-c3ad3a2c0a71b001bb29.js
	public/__generated__-updateCompany.chunk-c3ad3a2c0a71b001bb29.js.map
	public/__tests__-AccessKeyManager-test.chunk-bed6e34b29ee6fbd5d72.js
	public/__tests__-AccessKeyManager-test.chunk-bed6e34b29ee6fbd5d72.js.map
	public/__tests__-__snapshots__-AccessKeyManager-test-js-snap.chunk-07f6461ec4547a0878ef.js
	public/__tests__-__snapshots__-AccessKeyManager-test-js-snap.chunk-07f6461ec4547a0878ef.js.map

I'm using version 4 of react-universal-loader with Webpack 4.39.2.

@rtymchyk
Copy link

I think this is behaviour of webpack's resolve.weak (someone correct me if I'm wrong). It doesn't know what you want loaded at run-time, so it prepares references to everything possible in the directory. You could try using /* webpackExclude: ... */ magic comment.

@volkanunsal
Copy link
Author

volkanunsal commented Oct 26, 2019

@rtymchyk

So something like this?

/* webpackExclude: __generated__,__tests__ */
const Foo = universal(
    import(/* webpackExclude: __generated__,__tests__ */ 'Foo'));

@rtymchyk
Copy link

@volkanunsal You could also import directly the file that you want const CompanyEdit = universal(import('comps/Company/Edit/index'));

@volkanunsal
Copy link
Author

@rtymchyk Hm.... neither of those worked in my case.

@volkanunsal
Copy link
Author

volkanunsal commented Oct 26, 2019

Here is what did work. I also had to add webpackMode: "weak" to the import.

const CompanyEdit = universal(
  import(
    /* webpackExclude: /(__generated__|__tests__)/ */
    /* webpackMode: "weak" */
    'comps/Company/Edit'
  )
);

But that just bundles everything into a single chunk. It doesn't generate any other chunks.

@ScriptedAlchemy
Copy link
Collaborator

yep, you got it - use magic comments to exclude glob imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants