-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Allow configuration of use of contentHash for development #234
Changes from all commits
0ad6ad4
c965346
fad12e8
3092956
7bd1c71
5c22934
a7cc75b
04a602d
7c811ec
c64a514
98f7b8b
daf0532
15ed972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
) | ||
}) | ||
}) | ||
}) |
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' | ||
) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ const CompressionPlugin = require('compression-webpack-plugin') | |
const TerserPlugin = require('terser-webpack-plugin') | ||
const baseConfig = require('./base') | ||
const { moduleExists } = require('../utils/helpers') | ||
const config = require('../config') | ||
|
||
const getPlugins = () => { | ||
const plugins = [] | ||
|
@@ -76,4 +77,12 @@ const productionConfig = { | |
} | ||
} | ||
|
||
if (config.useContentHash === true) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`⚠️ WARNING | ||
Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed! | ||
Content hashes get added to the filenames regardless of setting useContentHash in 'shakapacker.yml' to false. | ||
`) | ||
} | ||
Comment on lines
+80
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just received this warning when deploying the Shakapacker v7 upgrade to production. Guessing from the warning, I would assume that the condition is incorrect. Shouldn't it state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reporting @justin808 fixed in #320 |
||
|
||
module.exports = merge(baseConfig, productionConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/shakacode/shakapacker/blob/master/package/env.js#LL13C1-L14C1
production for NODE_ENV
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May you elaborate?
isProduction
checked nodeEnv already and it seems that is how we check the environment in on JS side. Before also we were adding content hash ifisProduction
wastrue
.Should I do anything different?