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

writeToDisk doesn't work with multiple targets #2771

Closed
1 task done
Timmmm opened this issue May 22, 2020 · 13 comments
Closed
1 task done

writeToDisk doesn't work with multiple targets #2771

Timmmm opened this issue May 22, 2020 · 13 comments

Comments

@Timmmm
Copy link

Timmmm commented May 22, 2020

webpack version: 4.43.0
webpack-cli version: 3.3.11
webpack-dev-server version: 3.11.0
Node.js version: 14.0.0
Operating System: MacOS 10.14.6

  • This is a bug

If you have a webpack.config.js that exports multiple targets, e.g:

module.exports = [rendererConfig, mainConfig];

And you set this in one of them:

  devServer: {
    writeToDisk: true,
  },

Then no files are written to disk - the behaviour is identical to not setting it. If you add that setting to both targets then it correctly writes everything out to disk. But I would have expected that you can set that option in different targets separately.

Expected Behavior

It should write files to disk.

Actual Behavior

It does not write files to disk.

For Bugs; How can we reproduce the behavior?

Run webpack-dev-server with multiple targets, only one of which has writeToDisk set.

@alexander-akait
Copy link
Member

Please provide full configurations

@Timmmm
Copy link
Author

Timmmm commented May 22, 2020

I can't unfortunately (it's for a closed source app). Do you have a test config that has multiple targets somewhere?

@alexander-akait
Copy link
Member

@Timmmm Yes, and all works fine, please provide minimum configuration, we don't need you full configuration

@JohnStarich
Copy link

I'm seeing the same issue. I've created a repo and steps to reproduce to help demonstrate the problem: https://github.com/JohnStarich/webpack-multi-writeToDisk

Here are the configs for convenience:

webpack.config.js:

module.exports = [
  require('./webpack.config.ui.js'),
  require('./webpack.config.api.js'),
]

webpack.config.ui.js:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/ui/index.js',
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    port: 9000
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'Hello webpack',
    }),
  ],
};

webpack.config.api.js:

const path = require('path');

module.exports = {
  mode: 'production',
  entry: './src/api/index.js',
  target: 'node',
  devServer: {
    writeToDisk: true,
  },
  output: {
    path: path.resolve(__dirname, 'dist', 'api'),
  },
};

@JohnStarich
Copy link

I also noticed a separate issue: For some reason, setting the ui's devServer.contentBase and output.path to dist/ui failed to serve the UI entirely. Very strange, though not a big deal since I can make do with the default output path.

@alexander-akait
Copy link
Member

alexander-akait commented May 23, 2020

@JohnStarich contentBase and dist/ui are difference things, contentBase for public static assets, dist for webpack output, don't forget webpack output serve from memory

@JohnStarich
Copy link

Got it, thanks for clarifying!

For the devServer.writeToDisk issue, are there any issues with the above configs?
Let me know if there’s anything I can do to help 👍

@alexander-akait
Copy link
Member

For the devServer.writeToDisk issue, are there any issues with the above configs?

No issues 😄

@Airkro
Copy link

Airkro commented Oct 27, 2020

@evilebottnawi

How exactly webpack-dev-server handle webpack.config.js with multiple configs(different devServer config). We need more documentation about.

Like:

// webpack.config.js
module.exports = [
  {
    devServer: {
      port: 1234,
      publicPath: '/'
    }
  },
  {
    devServer: {
      port: 5678,
      publicPath: '/test/'
    }
  },
  {
    // don't want to use devServer
    devServer: false,
    target: 'node'
  }
];

@alexander-akait
Copy link
Member

alexander-akait commented Jun 7, 2021

@Airkro Sorry for delay, you can don't set devServer on the latest configuration, anyway false is good idea, I will implement this

@alexander-akait alexander-akait transferred this issue from webpack/webpack-dev-server Jun 7, 2021
@alexander-akait
Copy link
Member

@webpack/cli-team we need to allow set devServer: false, so we should fix it firstly here https://github.com/webpack/webpack/blob/master/schemas/WebpackOptions.json#L346, i.e. enum: [false]

@snitin315
Copy link
Member

On it 👍

@alexander-akait
Copy link
Member

Close in favor #2408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants