Preact-cli: Production build includes two copies of preact?

Created on 20 Jun 2017  路  11Comments  路  Source: preactjs/preact-cli

Steps to reproduce:

  1. npm install -g preact-cli
  2. preact create <app>
  3. cd <app>
  4. preact build --json
  5. Inspect stats.json using a Webpack stats analyzer (this one is from webpack-bundle-analyzer):

image

Expected behavior:

The preact library should only be included once in bundle.js.

Actual behavior:

It is included twice.

All 11 comments

Ah I think this is caused by preact-cli including preact as a dependency now. I think we can fix this by using an absolute path to Preact in the aliases setup.

Curious if @lukeed or @thangngoc89 see any issues in doing that.

@developit Should be no issue since webpack handles everything (internally) with absolute paths anyway.

Would love a PR for this btw if anyone has a few minutes. Otherwise I'll try to get around to it whenever I can.

I have given this a shot and it worked for me:
preact$: resolve(__dirname, '../../node_modules/preact/dist/preact.min.js'),

Is there a better way to do this? I am attaching the JSON file which I got while testing.

Please find the screenshot of the webpack bundle analyzer,

screen shot 2017-06-23 at 10 36 30 am

stats.json file: stats.json.zip

@developit @lukeed any suggestions? If this is fine, I would be happy to submit a PR.

We should have the alias attempt to use preact from $CWD/node_modules/preact and then maybe fall back to preact-cli's version. Otherwise that looks good, would love a PR.

Sure, will give that a try and see.

We should have the alias attempt to use preact from $CWD/node_modules/preact and then maybe fall back to preact-cli's version

Is this fine?

preact$: isProd ? resolve(__dirname, '../../node_modules/preact/dist/preact.min.js') : 'preact',

How about:

preact$: isProd ? resolve(env.cwd, 'node_modules/preact/dist/preact.min.js') : 'preact'

Cool, I did the same thing after I commented 馃槄

@developit @lukeed please have a look at it.

Yaaay, bundle size reduced from 26.8kb to 18.9kb.

@lukeed it failed 8 tests !! not sure why? Can you please have a look at the log?

https://paste.fedoraproject.org/paste/~djRyBcRUltRzRRaON3~qg

Was this page helpful?
0 / 5 - 0 ratings