symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 199 forks source link

configureRuntimeEnvironment does not work with "dev-server" environment #379

Open Fatal1stZ opened 6 years ago

Fatal1stZ commented 6 years ago

When i pass 'dev-server' environment into configureRuntimeEnvironment function, dev-server does not actually work. This is my cli: encore dev-server --hot --host=myhost port=123 --config-name=user (works) This is my call with configureRuntimeEnvironment: encore dev-server --hot --env.host=myhost --env.port=123 --config-name=terror (doesn't work)

module.exports = ( env = {} ) => { const { publicPath = "/bundles", environment = "dev-server", ...environmentOptions } = env let webpackConfigs = [] Encore.configureRuntimeEnvironment( environment, environmentOptions )

Lyrkan commented 6 years ago

Hi @Fatal1stZ,

I'm not sure what you're trying to achieve here, using configureRuntimeEnvironment() when you're calling encore seems a bit odd. This method was mainly added to be able to require('webpack.config.js') without calling yarn encore (which throws an error without it), for instance from a Karma config file.

As for why it doesn't work here... dev-server is a bit special compared to other environments since it sets additional variables based on the command line arguments.

In your second example you don't pass --host and --port, so the server get initialized with the default values (localhost/8080).

Fatal1stZ commented 6 years ago

It is actually called without npm encore when in production environment. I do pass port and host in node env, and it goes as environmentOptions into configureRuntimeEnvironment.

Lyrkan commented 6 years ago

Even if you're not calling it using npm/yarn you should still be able to use ./node_modules/.bin/encore without configureRuntimeEnvironment... unless you've installed Encore globally, which is not really supported.

Also, what do you mean exactly by "when in production environment"? Usually you'd compile everything before putting the resulting files on your production server.

Fatal1stZ commented 6 years ago

I meant I used webpack-encore with parallel-webpack, so I needed to provide production env via configureRuntimeEnvironment.

Lyrkan commented 6 years ago

I needed to provide production env via configureRuntimeEnvironment

@Fatal1stZ Sorry but I still don't understand... calling configureRuntimeEnvironment should work fine with the production env, whether or not you are using parallel-webpack. What error did you run into?

And if you meant to say dev-server instead of production I'm not sure parallel-webpack works fine with it either, see https://github.com/trivago/parallel-webpack/issues/18.