webpack --watch does not generate build.js file

Asked 2 years ago, Updated 2 years ago, 93 views

Generated in the following steps:
$webpack

The following command does not create build.js
$webpack-dev-server --progress --colors --watch --config webpack.config.js

webpack.config.jsContents

//webpack.config.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,
          presents: [
            '@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
  }
}

Logging at $watch

$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:969fbd8 febed56bc8d48
Version—webpack 4.20.2
Time: 2582ms
Built at: 2018-10-10 18:22:34
          Asset Size 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} [build]
[./node_modules/loglevel/lib/loglevel.js] 7.68KiB{main} [build]
[./node_modules/mobx-react/index.module.js] 43.2KiB {main} [build]
[./node_modules/punycode/punycode.js] 14.3 KiB {main} [build]
[./node_modules/react-dom/index.js] 1.33 KiB {main} [build]
[./node_modules/react/index.js] 190 bytes {main} [build]
[./node_modules/trip-ansi/index.js] 161 bytes {main} [build]
[./node_modules/url/url.js] 22.8 KiB {main} [build]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:9000] (webpack) - dev-server/client?http://localhost:9000 7.78KiB{main} [build]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack) - dev-server/client/overlay.js 3.58KiB{main} [build]
[0] multi(webpack)-dev-server/client?http://localhost:9000./src/app.js40 bytes {main} [build]
[./node_modules/webpack-dev-server/client/socket.js] (webpack) - dev-server/client/socket.js 1.05 KiB {main} [build]
[./node_modules/webpack/hot sync^\.\/log$] (webpack)/hot sync nonrecursive^\.\/log $170 bytes {main} [build]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js77 bytes {main} [build]
[./src/app.js] 2.73KiB {main} [build]
    + 25 hidden modules
i "wdm"—Compiled successfully.

Each version

"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"

Is the latest version no longer generating files when watching?

webpack

2022-09-30 11:10

1 Answers

webpack --watch and webpack-dev-server are different.webpack-dev-server provides a browser-accessible server, but does not have the ability to save the product to the file system (see ).It must be webpack --watch in order for it to be saved to the file.

To have your product saved to a file while using webpack-dev-server, you can use write-file-webpack-plugin.


2022-09-30 11:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.