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

Only include dev-server parts if for dev server #2644

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion package/__tests__/development.js
Expand Up @@ -11,9 +11,10 @@ describe('Development environment', () => {
describe('toWebpackConfig', () => {
beforeEach(() => jest.resetModules())

test('should use development config and environment', () => {
test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
process.env.RAILS_ENV = 'development'
process.env.NODE_ENV = 'development'
process.env.WEBPACK_DEV_SERVER = 'YES'
const { environment } = require('../index')

const config = environment.toWebpackConfig()
Expand All @@ -26,5 +27,17 @@ describe('Development environment', () => {
}
})
})

test('should use development config and environment if WEBPACK_DEV_SERVER', () => {
process.env.RAILS_ENV = 'development'
process.env.NODE_ENV = 'development'
process.env.WEBPACK_DEV_SERVER = undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is per the definition here: https://github.com/webpack/webpack-dev-server/pull/1929/files#diff-15fb51940da53816af13330d8ce69b4eR66

if (!process.env.WEBPACK_DEV_SERVER) {
  process.env.WEBPACK_DEV_SERVER = true;
}

const { environment } = require('../index')

const config = environment.toWebpackConfig()
expect(config.output.path).toEqual(resolve('public', 'packs'))
expect(config.output.publicPath).toEqual('/packs/')
expect(config.devServer).toEqual(undefined)
})
})
})
72 changes: 39 additions & 33 deletions package/environments/development.js
Expand Up @@ -7,41 +7,47 @@ module.exports = class extends Base {
constructor() {
super()

if (devServer.hmr) {
this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin())
this.config.output.filename = '[name]-[hash].js'
}

this.config.merge({
mode: 'development',
devtool: 'cheap-module-source-map',
devServer: {
clientLogLevel: 'none',
compress: devServer.compress,
quiet: devServer.quiet,
disableHostCheck: devServer.disable_host_check,
host: devServer.host,
port: devServer.port,
https: devServer.https,
hot: devServer.hmr,
contentBase,
inline: devServer.inline,
useLocalIp: devServer.use_local_ip,
public: devServer.public,
publicPath,
historyApiFallback: {
disableDotRule: true
},
headers: devServer.headers,
overlay: devServer.overlay,
stats: {
entrypoints: false,
errorDetails: true,
modules: false,
moduleTrace: false
},
watchOptions: devServer.watch_options
}
devtool: 'cheap-module-source-map'
})

if (process.env.WEBPACK_DEV_SERVER
&& process.env.WEBPACK_DEV_SERVER !== 'undefined') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I ran the tests, for some reason, the undefined comes as a string for comparison.

if (devServer.hmr) {
this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin())
this.config.output.filename = '[name]-[hash].js'
}

this.config.merge({
devServer: {
clientLogLevel: 'none',
compress: devServer.compress,
quiet: devServer.quiet,
disableHostCheck: devServer.disable_host_check,
host: devServer.host,
port: devServer.port,
https: devServer.https,
hot: devServer.hmr,
contentBase,
inline: devServer.inline,
useLocalIp: devServer.use_local_ip,
public: devServer.public,
publicPath,
historyApiFallback: {
disableDotRule: true
},
headers: devServer.headers,
overlay: devServer.overlay,
stats: {
entrypoints: false,
errorDetails: true,
modules: false,
moduleTrace: false
},
watchOptions: devServer.watch_options
}
})
}
}
}