简体   繁体   中英

Overriding Webpack 4 Entry Point

Here's the directory of my project:

   -node_modules
   -src
       -client
          -js
          -styles
          -views
          -index.js
          -webpack.config.js
       -server
   -.babelrc
   -package
   -package-lock
   -README.md
   -webpack.dev
   -webpack.prod

Here's the content of my webpack.config.js

const path = require('path')
const webpack = require('webpack')

module.exports = {
    mode: 'none',
    //entry: path.resolve(__dirname) + './src/client/index.js',

    module: {
        rules: [
            {
                test: '/\.js$./',
                exclude: /node_modules/,
                loader: "babel-loader"
            }
        ]
    }
}

I want to override the default entry point inside webpack.config.js to point to the index.js file in the same level.

By default, if I have the index.js file inside the src directory, without specifying the entry point, it works as expected.

I have tried changing the entry points like this:

entry: path.resolve(__dirname, './src/client/index.js'),

entry: path.resolve(__dirname, 'src') + 'client/index.js',

entry: path.resolve(__dirname, './src/index.js'),

entry: path.resolve(__dirname) + '/src/client/index.js',

entry: path.resolve(__dirname) + './src/client/index.js'

I'm using a windows 10 Operating System.

module.exports = {
  entry: './index.js'
};

Ref: https://webpack.js.org/concepts/entry-points/


Alternatively, you can also use

module.exports = {
  entry: require.resolve('./index')
};

Ref: https://nodejs.org/api/modules.html#modules_require_resolve_request_options

What solved my problem was to move the webpack.config.js file to the root folder and then configured the entry point like this:

module.exports = {
    ...    
    entry: './src/client/index.js',
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM