

以下の手順では生成されます。  
`$ webpack`

以下のコマンドでは `build.js` が作成されません  
`$ webpack-dev-server --progress --colors --watch --config webpack.config.js`

`webpack.config.js`の中身

[code]

    // webpack.confing.js
    
    const path = require('path')
    
    module.exports = {
      mode: 'development',
      entry: './src/app.js',
      output: {
        path: path.resolve(__dirname, './'),
        filename: 'public/build.js'
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
              babelrc: false,
              presets: [
                '@babel/preset-env',
                '@babel/preset-react'
              ],
              plugins: [
                ['@babel/plugin-proposal-decorators', {
                  legacy: true
                }],
                ['@babel/plugin-proposal-class-properties', {
                  loose: true
                }]
              ]
            }
          },
          {
            test: /\.css$/,
            use: ['style-loader', 'css-loader?modules']
          },
          {
            test: /\.scss$/,
            use: ['style-loader', 'css-loader', 'sass-loader']
          }
        ]
      },
      resolve: {
        extensions: ['.js', '.jsx']
      },
      devServer: {
        contentBase: path.join(__dirname, './'),
        compress: true,
        port: 9000
      }
    }
    
[/code]

`$ watch`時のログ

[code]

    $ webpack-dev-server --progress --colors --watch --config webpack.config.js
     10% building modules 1/1 modules 0 activei ｢wds｣: Project is running at http://localhost:9000/
    i ｢wds｣: webpack output is served from /
    i ｢wds｣: Content not from webpack is served from path
    i ｢wdm｣: Hash: 969fbd8febed56bc8d48
    Version: webpack 4.20.2
    Time: 2582ms
    Built at: 2018-10-10 18:22:34
              Asset      Size  Chunks             Chunk Names
    public/build.js  1.29 MiB    main  [emitted]  main
    Entrypoint main = public/build.js
    [./node_modules/ansi-html/index.js] 4.16 KiB {main} [built]
    [./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built]
    [./node_modules/mobx-react/index.module.js] 43.2 KiB {main} [built]
    [./node_modules/punycode/punycode.js] 14.3 KiB {main} [built]
    [./node_modules/react-dom/index.js] 1.33 KiB {main} [built]
    [./node_modules/react/index.js] 190 bytes {main} [built]
    [./node_modules/strip-ansi/index.js] 161 bytes {main} [built]
    [./node_modules/url/url.js] 22.8 KiB {main} [built]
    [./node_modules/webpack-dev-server/client/index.js?http://localhost:9000] (webpack)-dev-server/client?http://localhost:9000 7.78 KiB {main} [built]
    [./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main} [built]
    [0] multi (webpack)-dev-server/client?http://localhost:9000 ./src/app.js 40 bytes {main} [built]
    [./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
    [./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
    [./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {main} [built]
    [./src/app.js] 2.73 KiB {main} [built]
        + 25 hidden modules
    i ｢wdm｣: Compiled successfully.
    
[/code]

各バージョン

[code]

    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.9"
    
[/code]

最新バージョンではwatch時にファイルが生成されなくなったのでしょうか？


CC BY-SA 4.0
2018-10-10T09:40:18.313
49137
2019-08-21T06:01:50.223
20868
question
webpack
webpack --watch で build.js ファイルが生成されません


**`webpack --watch`と`webpack-dev-server`は別物です。**`webpack-dev-
server`はブラウザからアクセス可能なサーバーを提供する代わりに、生成物をファイルシステムに保存する機能はありません（参考：[Write bundle
to disk](https://github.com/webpack/webpack-dev-
server/issues/62)）。ファイルに保存してもらうためには`webpack --watch`とする必要があります。

webpack-dev-serverを使いつつ生成物をファイルに保存してもらう方法としては、[write-file-webpack-
plugin](https://github.com/gajus/write-file-webpack-plugin)を使う方法があるようです。


CC BY-SA 4.0
2018-10-10T10:47:38.720
49141
2018-10-10T10:47:38.720
30079
49137
answer