问题
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.
回答1:
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
回答2:
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',
...
}
来源:https://stackoverflow.com/questions/58915153/overriding-webpack-4-entry-point