Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

node.js - Fixing Webpack's Watch Option

I had code that worked just fine, but now I've updated some packages, especially webpack, and I'm getting some warnings that I'd like to remove.

When I run the command npm run watch, I get the following error:

[DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] DeprecationWarning: A 'callback' argument need to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.

My package.json is as follows:

{
    "name": "simple-flask-react-template",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "build": "webpack -p --progress --config webpack.config.js",
        "dev-build": "webpack --progress -d --config webpack.config.js",
        "test": "echo "Error: no test specified" && exit 1",
        "watch": "webpack --progress -d --config webpack.config.js --watch"
    },
    "author": "jadiker",
    "license": "None",
    "homepage": "https://github.com/rbarbaresco/simple-flask-react-template#readme",
    "devDependencies": {
        "babel-core": "^6.26.3",
        "babel-loader": "^7.1.5",
        "babel-preset-env": "^1.7.0",
        "babel-preset-react": "^6.24.1",
        "bootstrap": "^4.2.1",
        "css-loader": "^2.1.0",
        "file-loader": "^3.0.1",
        "jquery": "^3.5.1",
        "popper.js": "^1.14.7",
        "react": "^16.7.0",
        "react-dom": "^16.7.0",
        "webpack": "^5.11.1",
        "webpack-cli": "^3.3.10"
    },
    "babel": {
        "presets": [
            "env",
            "react"
        ]
    },
    "dependencies": {
        "@fortawesome/fontawesome-svg-core": "^1.2.28",
        "@fortawesome/free-solid-svg-icons": "^5.13.0",
        "@fortawesome/react-fontawesome": "^0.1.9",
        "query-string": "^6.11.1",
        "react-router-dom": "^5.1.2"
    }
}

My webpack.config.js is as follows:

const webpack = require('webpack');
const config ={
    mode: 'development',
    entry: {
        login: './js/login.jsx',
        signup: './js/signup.jsx',
        index: './js/index.jsx',
        search: './js/search.jsx',
        ask: './js/ask.jsx',
        question: './js/question.jsx',
        help: './js/help.jsx',
        test: './js/test.jsx',
    },
    devtool: 'inline-source-map',
    output: {
        path: __dirname + '/dist/bundle',
        filename: '[name].bundle.js',
    },
    resolve:{
        extensions:[
            '.js',
            '.jsx',
            '.css'
        ]
    },
    module:{
        rules:[
            {
                test:/.jsx?/,
                exclude:/node_modules/,
                use:'babel-loader'
            },
            {
                test:/.(jpe?g|png|gif|svg)$/i,
                loader:"file-loader",
            },
            {
                test:/.css$/,
                use:[
                    'css-loader'
                ],

            },

        ]
    }
};


module.exports = config;

What can I change in the code in order to get that warning to go away?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...