如何正确配置webpack?

我认为配置 webpack 时遇到了一些问题。我正在一步步制作教程,但它不起作用。

错误] 无法在项目商店上执行目标 com.github.eirslett:frontend-maven-plugin:1.10.3:webpack (webpack build):无法运行任务:“webpack.js”失败。org.apache.commons.exec.ExecuteException:进程退出并出现错误:2

错误看起来像:

[INFO] ERROR in ./src/main/js/app.js

[INFO] Module not found: Error: Can't resolve './client' in '/home/kk/IdeaProjects/e-commerce/src/main/js'

[INFO]  @ ./src/main/js/app.js 29:13-32

[INFO] 

[INFO] ERROR in ./src/main/js/app.js

[INFO] Module not found: Error: Can't resolve 'react' in '/home/kk/IdeaProjects/e-commerce/src/main/js'

[INFO]  @ ./src/main/js/app.js 25:12-28

[INFO] 

[INFO] ERROR in ./src/main/js/app.js

[INFO] Module not found: Error: Can't resolve 'react-dom' in '/home/kk/IdeaProjects/e-commerce/src/main/js'

[INFO]  @ ./src/main/js/app.js 27:15-35


webpack.config.js:


var path = require('path');


module.exports = {

    entry: './src/main/js/app.js',

    devtool: 'sourcemaps',

    cache: true,

    mode: 'development',

    output: {

        path: __dirname,

        filename: './src/main/resources/static/built/bundle.js'

    },

    module: {

        rules: [

            {

                test: path.join(__dirname, '.'),

                exclude: /(node_modules)/,

                use: [{

                    loader: 'babel-loader',

                    options: {

                        presets: ["@babel/preset-env", "@babel/preset-react"]

                    }

                }]

            }

        ]

    }


};

应用程序.js:


'use strict';


const React = require('react');

const ReactDOM = require('react-dom');

const client = require('./client');


class App extends React.Component {...}

class EmployeeList extends React.Component{...}

class Employee extends React.Component{...}

ReactDOM.render(<App/>, document.getElementById('react'))


慕森王
浏览 83回答 1
1回答

当年话下

看来您需要从提供的教程中复制粘贴package.json片段并运行npm i
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript