Skip to content

Commit

Permalink
feature #483 Add new methods isDev() and isDevServer() (Kocal)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Add new methods `isDev()` and `isDevServer()`

Hi,

This PR adds two new methods `isDev()` and `isDevServer()` aside the already existing `isProduction()` method.

On a project at work, we should configure webpack-encore only when we are running the dev-server.
There is the property `runtimeConfig.useDevServer` but we don't have access to `runtimeConfig` in our `webpack.config.js`.

I know we can do this:
```js
const config = Encore.getWebpackConfig();

if (config.devServer) {
  // ....
}
```

but it means that we can't use webpack-encore methods:
```js
if (Encore.isDevServer()) {
  Encore
    .setPublicPath('http://app.vm:8080/build/')
    .setManifestKeyPrefix('build/')
}
```

Also I tried to add some tests but I didn't find tests for `isProduction()` :(

Thanks!

Commits
-------

c702533 Add new methods `isDev()` and `isDevServer()`
  • Loading branch information
weaverryan committed Jan 5, 2019
2 parents bf6fb63 + c702533 commit 2d1d6d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,24 @@ class Encore {
return webpackConfig.isProduction();
}

/**
* Is this currently a "dev" build?
*
* @returns {boolean}
*/
isDev() {
return webpackConfig.isDev();
}

/**
* Is this currently a "dev-server" build?
*
* @returns {boolean}
*/
isDevServer() {
return webpackConfig.isDevServer();
}

/**
* Use this at the bottom of your webpack.config.js file:
*
Expand Down
8 changes: 8 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ class WebpackConfig {
isProduction() {
return this.runtimeConfig.environment === 'production';
}

isDev() {
return this.runtimeConfig.environment === 'dev';
}

isDevServer() {
return this.isDev() && this.runtimeConfig.useDevServer;
}
}

module.exports = WebpackConfig;

0 comments on commit 2d1d6d6

Please sign in to comment.