-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuration of use of contentHash for development (#234)
To enable/disable the usage of contentHash in any node environment (specified using the `NODE_ENV` environment variable), add/modify `useContentHash` with a boolean value in `config/shakapacker.yml`. This feature is disabled for all environments except production by default. You may not disable the content hash for a `NODE_ENV` of production as that would break the browser caching of assets. Notice that despite the possibility of enabling this option for the development environment, [it is not recommended](https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling).
- Loading branch information
Showing
9 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* global test expect, describe, afterAll, beforeEach */ | ||
|
||
const { chdirTestApp, resetEnv } = require('../../utils/helpers') | ||
const rootPath = process.cwd() | ||
chdirTestApp() | ||
|
||
describe('Development specific config', () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
resetEnv() | ||
process.env['NODE_ENV'] = 'development' | ||
}) | ||
afterAll(() => process.chdir(rootPath)) | ||
|
||
describe('with config.useContentHash = true', () => { | ||
test('sets filename to use contentHash', () => { | ||
const config = require("../../config"); | ||
config.useContentHash = true | ||
const environmnetConfig = require('../development') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name]-[contenthash].chunk.js' | ||
) | ||
}) | ||
}) | ||
|
||
describe('with config.useContentHash = false', () => { | ||
test('sets filename without using contentHash', () => { | ||
const config = require("../../config"); | ||
config.useContentHash = false | ||
const environmnetConfig = require('../development') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name].chunk.js' | ||
) | ||
}) | ||
}) | ||
|
||
describe('with unset config.useContentHash', () => { | ||
test('sets filename without using contentHash', () => { | ||
const config = require("../../config"); | ||
delete config.useContentHash | ||
const environmnetConfig = require('../development') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name].chunk.js' | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* global test expect, describe, afterAll, beforeEach */ | ||
|
||
const { chdirTestApp, resetEnv } = require('../../utils/helpers') | ||
const rootPath = process.cwd() | ||
chdirTestApp() | ||
|
||
describe('Production specific config', () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
resetEnv() | ||
process.env['NODE_ENV'] = 'production' | ||
}) | ||
afterAll(() => process.chdir(rootPath)) | ||
|
||
describe('with config.useContentHash = true', () => { | ||
test('sets filename to use contentHash', () => { | ||
const config = require("../../config"); | ||
config.useContentHash = true | ||
const environmnetConfig = require('../production') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name]-[contenthash].chunk.js' | ||
) | ||
}) | ||
}) | ||
|
||
describe('with config.useContentHash = false', () => { | ||
test('sets filename to use contentHash', () => { | ||
const config = require("../../config"); | ||
config.useContentHash = false | ||
const environmnetConfig = require('../production') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name]-[contenthash].chunk.js' | ||
) | ||
}) | ||
}) | ||
|
||
describe('with unset config.useContentHash', () => { | ||
test('sets filename to use contentHash', () => { | ||
const config = require("../../config"); | ||
delete config.useContentHash | ||
const environmnetConfig = require('../production') | ||
|
||
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js') | ||
expect(environmnetConfig.output.chunkFilename).toEqual( | ||
'js/[name]-[contenthash].chunk.js' | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters