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

Remove webpack dependency on production #23

Closed
papigers opened this issue Aug 7, 2016 · 17 comments
Closed

Remove webpack dependency on production #23

papigers opened this issue Aug 7, 2016 · 17 comments

Comments

@papigers
Copy link
Contributor

papigers commented Aug 7, 2016

This isn't really an issue, since it really solvable without any changes in the code, but I'll explain. I want to remove the dependency of webpack in the production build, since i deploy the built bundle already.

My problem is that universal-webpack forces me to put webpack in my (non dev-)dependencies:

import { server_configuration } from 'universal-webpack'
import settings from './universal-webpack-settings'
import configuration from './webpack.config' // THIS requires webpack and another things which should belong only to dev: postcss plugins etc...

export default server_configuration(configuration, settings)

I've looked into the server.js file and it seems it only requires the context and the output paths, so it is possible to pass just those paths and be done with it, requiring the entire webpack config is a bit unnecessary.

So like I said, it really isn't an issue since we can just change it to:

import { server_configuration } from 'universal-webpack'
import settings from './universal-webpack-settings'

export default server_configuration({
  context: /* context path */,
  output: {
    path: /* server build output */
  }
}, settings)

But maybe document it?

@catamphetamine
Copy link
Owner

Ok, added this info to the docs.

@adailey14
Copy link

Hi guys, I'm trying to understand this, because I also want to remove webpack from my production dependencies.

What I don't understand, is it seems like server_configuration from universal_webpack still requires webpack. So even by stubbing the configuration passed into server_configuration, you haven't eliminated the production dependency on webpack. Is that right? Or can you help me understand that? Thank you in advance.

@catamphetamine
Copy link
Owner

it seems like server_configuration from universal_webpack still requires webpack.

What makes you think so

@adailey14
Copy link

I thought so from looking at the source file:
universal-webpack/source/server configuration.js

At line 3 it imports webpack:
import webpack from 'webpack'

Am I looking in the wrong place?

@catamphetamine
Copy link
Owner

Yes, it uses webpack for its plugins: it removes webpack.HotModuleReplacementPlugin and webpack.optimize.CommonsChunkPlugin and also adds webpack.optimize.LimitChunkCountPlugin.

The original poster said:

since i deploy the built bundle already.

Therefore, currently webpack is used during build but it's not used when running the built bundle

@adailey14
Copy link

Ah I understand! Thank you.

@adailey14
Copy link

Ok I understand what was throwing me off now. server_configuration() does require a relatively full webpack configuration. It's server() that only requires context and output: {path: }. This is what you updated in the documentation - I think in @papigers initial post he shows an example using server_configuration() but really he meant server().

@adailey14
Copy link

Hi sorry to keep harping on this, I appreciate any help.

I find that I am still hitting a dependency on webpack. Running this line in production is trying to find webpack:

import { server } from 'universal-webpack';

If I go into index.common.js in node_modules/universal-webpack and comment out these lines:

server_configuration : require('./build/server configuration').default,
client_configuration : require('./build/client configuration').default,
serverConfiguration : require('./build/server configuration').default,
clientConfiguration : require('./build/client configuration').default,

Then I can get it to work. So it seems that just by importing universal-webpack I am hitting the dependency on webpack. So I can also get around this by requiring server like this:

import server from 'universal-webpack/build/server';

instead of like this:

import { server } from 'universal-webpack';

Does this make sense?

@catamphetamine
Copy link
Owner

Yes, it does: seems that indeed webpack is required for running the .common.js bundle.
Presumably this is fixed in Webpack 2 because it should "tree shake" the unused dependencies.
But for Webpack 1, as a workaround, import server from 'universal-webpack/build/server' is gonna work without any difference.

@adailey14
Copy link

Ok thank you, that makes sense.

@catamphetamine
Copy link
Owner

Oh, disregard my comment above: here Node.js is used, not Webpack. And Node.js doesn't "tree shake". So, yes, the workaround you proposed seems to be the one:

import server from 'universal-webpack/build/server'

@adailey14
Copy link

Great, seems like it works. I wonder what is the right way to represent universal-webpack's dependency on webpack. I guess it might make sense to break up the build_configuration aspect from the runtime aspect. Then the build_configuration part would depend on webpack and the runtime part would not. Not sure that is worth doing just interesting to think about.

@catamphetamine
Copy link
Owner

And how would you require it then?
You only have one index.js and one way or another it's gonna be a separate require() from lib.

@catamphetamine
Copy link
Owner

I can make a simple shortcut though.
Like universal-webpack/server.
Yeah, I guess I'll make it now.

@adailey14
Copy link

Yeah I don't know enough about structuring npm packages...

@catamphetamine
Copy link
Owner

I added two new exports:

import { client, server } from 'universal-webpack/config'
import startServer from 'universal-webpack/server'

You can test these in the newly released version.

@adailey14
Copy link

Very cool, I won't be able to test for a while. I'm still on Webpack 1 so not ready for the latest version of universal-webpack. Hoping to have some time to make the upgrade soon.

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