webpack.js.org icon indicating copy to clipboard operation
webpack.js.org copied to clipboard

Webpack only emits file in development mode

Open Sombian opened this issue 4 years ago • 7 comments

Bug report

What is the current behavior?

Webpack only emits file in development mode.

If the current behavior is a bug, please provide the steps to reproduce.

const compiler_main = webpack({
	...main,
	mode: "production",
	devtool: "inline-nosources-cheap-module-source-map",
}, () => {
	const compiler_preload = webpack({
		...preload,
		mode: "production",
		devtool: "inline-nosources-cheap-module-source-map",
	}, () => {
		const compiler_renderer = webpack({
			...renderer,
			mode: "production",
			devtool: "inline-nosources-cheap-module-source-map",
		}, () => {
			// rest code goes here
		});
	});
});

What is the expected behavior?

Webpack emits file regardless of current mode.

Other relevant information: webpack version: 5.47.1 Node.js version: node-v16.6.0-x64 Operating System: Windows 10 Pro Additional tools:

Sombian avatar Jul 30 '21 19:07 Sombian

For maintainers only:

  • [ ] webpack-4
  • [ ] webpack-5
  • [ ] bug
  • [ ] critical-bug
  • [ ] enhancement
  • [ ] documentation
  • [ ] performance
  • [ ] dependencies
  • [ ] question

webpack-bot avatar Jul 30 '21 19:07 webpack-bot

You should run ‘close’ after compilation, please look at docs https://webpack.js.org/api/node/#run

alexander-akait avatar Jul 31 '21 11:07 alexander-akait

Cc @chenxsan i think we should update all examples with close

alexander-akait avatar Jul 31 '21 11:07 alexander-akait

You should run ‘close’ after compilation, please look at docs https://webpack.js.org/api/node/#run

tried but still the same. I got working workaround though

	mode: "development",
	devtool: "inline-nosources-cheap-module-source-map",
	plugins: [
		new webpack.DefinePlugin({
			"process.env": {
				"NODE_ENV": JSON.stringify("production")
			}
		})
	]

Sombian avatar Jul 31 '21 16:07 Sombian

Cc @chenxsan i think we should update all examples with close

Per https://webpack.js.org/blog/2020-10-10-webpack-5-release/#compiler-idle-and-close:

The webpack() façade automatically calls close when being passed a callback.

So in this specific issue, there seems no need to close compilers.

But there's indeed one example needs an update with the close method.

chenxsan avatar Aug 01 '21 10:08 chenxsan

@Sombian Maybe you could create a reproducible repository so we can investigate?

chenxsan avatar Aug 01 '21 10:08 chenxsan

@Sombian Maybe you could create a reproducible repository so we can investigate?

Repo: https://github.com/Any-Material/nozomi-material

So, it seems, mode must be set to development, but since I want to optimize / minimize code for production, development output isnt quite appealing to me, then again, production won't emit files what so ever.

	plugins: [
		new webpack.DefinePlugin({
			"process.env": {
				"NODE_ENV": JSON.stringify("production")
			}
		})
	]

Thats why I added this section of code. Quick thing to note is, setting proccess.env.NODE_ENV directly doesn't do anything.

Sombian avatar Aug 01 '21 14:08 Sombian