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

Support to extend default webpacker env for non-standard env #1355

Closed

Conversation

tricknotes
Copy link
Contributor

@tricknotes tricknotes commented Mar 15, 2018

Currently, the non-standard env is allowed to use but any webpacker default config is ignored.
Especially, the developer who use "staging" expects that the environment is almost the same as "production".

This commit allows to specify the default webpacker env to be extended by non-standard env.

If someone want to extend webpacker env without this commit, the following change is required.

diff --git a/config/webpack/staging.js b/config/webpack/staging.js
index d7346478..77bb3afa 100644
--- a/config/webpack/staging.js
+++ b/config/webpack/staging.js
@@ -1,3 +1,4 @@
-const environment = require('./environment');
+const Environment = require('@rails/webpacker/package/environments/production');
+const environment = new Environment();
    
module.exports = environment.toWebpackConfig();

This PR depends on #1350 due to support for non-standard env :<

The Rails defined custom env is allowed by rails#1304.
However Webpacker custom env is not allowed for now.

```
/Users/tricknotes/dummy-app/node_modules/@rails/webpacker/package/config.js:16
    delete defaults.extensions
           ^

TypeError: Cannot convert undefined or null to object
```

This commit allows using user defined env for Webpacker.
@tricknotes tricknotes force-pushed the extend-default-webpacker-env branch 2 times, most recently from 53f790a to 0588462 Compare March 15, 2018 14:18
Currently, the non-standard env is allowed to use but any webpacker
default config is ignored.
Especially, the developer who use "staging" expects that the environment
is almost the same as "production".

This commit allows to specify the default webpacker env to be extended
by non-standard env.

If someone want to extend webpacker env without this commit, the
following change is required.
``` diff
diff --git a/config/webpack/staging.js b/config/webpack/staging.js
index d7346478..77bb3afa 100644
--- a/config/webpack/staging.js
+++ b/config/webpack/staging.js
@@ -1,3 +1,4 @@
-const environment = require('./environment');
+const Environment = require('@rails/webpacker/package/environments/production');
+const environment = new Environment();

 module.exports = environment.toWebpackConfig();
```
@gauravtiwari
Copy link
Member

Thanks @tricknotes for your contribution. Just merged #1359, which solves this issue.

@tricknotes
Copy link
Contributor Author

Ah, right!
Thanks, it makes sense. :-)

@tricknotes tricknotes deleted the extend-default-webpacker-env branch March 21, 2018 02:33
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

Successfully merging this pull request may close these issues.

2 participants