Skip to content

Commit 2d1d6d6

Browse files
committed
feature #483 Add new methods isDev() and isDevServer() (Kocal)
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()`
2 parents bf6fb63 + c702533 commit 2d1d6d6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,24 @@ class Encore {
10721072
return webpackConfig.isProduction();
10731073
}
10741074

1075+
/**
1076+
* Is this currently a "dev" build?
1077+
*
1078+
* @returns {boolean}
1079+
*/
1080+
isDev() {
1081+
return webpackConfig.isDev();
1082+
}
1083+
1084+
/**
1085+
* Is this currently a "dev-server" build?
1086+
*
1087+
* @returns {boolean}
1088+
*/
1089+
isDevServer() {
1090+
return webpackConfig.isDevServer();
1091+
}
1092+
10751093
/**
10761094
* Use this at the bottom of your webpack.config.js file:
10771095
*

lib/WebpackConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ class WebpackConfig {
688688
isProduction() {
689689
return this.runtimeConfig.environment === 'production';
690690
}
691+
692+
isDev() {
693+
return this.runtimeConfig.environment === 'dev';
694+
}
695+
696+
isDevServer() {
697+
return this.isDev() && this.runtimeConfig.useDevServer;
698+
}
691699
}
692700

693701
module.exports = WebpackConfig;

0 commit comments

Comments
 (0)