Webpacker: Removing cache from output filenames

Created on 10 Oct 2017  路  3Comments  路  Source: rails/webpacker

Hi there,

I was trying to figure out how to remove the cache part of file outputs in the test environment, but I could not figure out how to change the config.output.filename property in config/webpack/test.js

Is it possible and could you give me a pointer how to achieve this please?

The reason I'm doing this is to load some webpack generated assets into an old teaspoon testing suite, as I'm trying to move over our asset compiling from sprockets to webpack. Hope that makes sense.

Thanks!

All 3 comments

@eriknygren Yes, that's the correct way to do it in test.js file, config.output.filename = '[name].js'

// config/webpack/test.js
const config = environment.toWebpackConfig()
config.output.filename = '[name].js'

module.exports = config

Aaah I just had it in the wrong order, didn't realise you had to call .toWebpackConfig() first before making any amends. Thanks a lot @gauravtiwari 馃檹

@gauravtiwari how would I achieve this in newer versions of webpacker when test.js is not a thing anymore? the output filename doesn't seem to be configurable in the webpacker.yml file

Edit:
Got it working by adding this to environment.js:

if (process.env.RAILS_ENV === 'test') {
  environment.config.output.filename = '[name].js';
}

If there's a nicer way I'd love to know, but at least it's working. Thanks for all your hard work

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankFang picture FrankFang  路  3Comments

towry picture towry  路  3Comments

amandapouget picture amandapouget  路  3Comments

ankitrg picture ankitrg  路  3Comments

itay-grudev picture itay-grudev  路  3Comments