Skip to content

Commit

Permalink
Allow custom env for Webpacker
Browse files Browse the repository at this point in the history
The Rails defined custom env is allowed by #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.
  • Loading branch information
tricknotes committed Mar 14, 2018
1 parent 811796a commit 48f6c08
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defaultConfigPath = require.resolve('../lib/install/config/webpacker.yml')
const configPath = resolve('config', 'webpacker.yml')

const getConfig = () => {
const defaults = safeLoad(readFileSync(defaultConfigPath), 'utf8')[env]
const defaults = safeLoad(readFileSync(defaultConfigPath), 'utf8')[env] || {}
const app = safeLoad(readFileSync(configPath), 'utf8')[env]

if (isArray(app.extensions) && app.extensions.length) {
Expand Down
14 changes: 14 additions & 0 deletions test/env_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ def test_custom
end
end

def test_custom_with_user_defined
with_node_env("cucumber") do
reloaded_config
assert_equal Webpacker.env, "cucumber"
end
end

def test_fallback
with_node_env("not-defined") do
reloaded_config
assert_equal Webpacker.env, "production"
end
end

def test_default
assert_equal Webpacker::Env::DEFAULT, "production"
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_app/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ production:

# Cache manifest.json for performance
cache_manifest: true

cucumber:
<<: *default
compile: true

# Compile test packs to a separate directory
public_output_path: packs-cucumber

0 comments on commit 48f6c08

Please sign in to comment.