[英]Webpack 4 ./src directory not found
I am trying to split the webpack config to base, dev and prod configs. 我正在尝试将webpack配置拆分为基础配置,开发配置和产品配置。 Here is my entry section of
webpack.base.babel.js
file 这是我的
webpack.base.babel.js
文件的输入部分
module.exports = options => ({
mode: options.mode,
entry: options.entry,
output: Object.assign(
{
// Compile into js/build.js
path: path.resolve(process.cwd(), 'build'),
publicPath: '/',
},
options.output,
), // Merge with env dependent settings
Here is the entry section of webpackdev.babel.js
file: 这是
webpackdev.babel.js
文件的输入部分:
module.exports = require('./webpack.base.babel')({
mode: 'development',
// Add hot reloading in development
entry: [
require.resolve('react-app-polyfill/ie11'),
'webpack-hot-middleware/client?reload=true',
path.join(process.cwd(), 'app/app.js'),
],
// Don't use hashes in dev mode for better performance
output: {
filename: '[name].js',
chunkFilename: '[name].chunk.js',
},
My start script in package.json looks like: "start": "webpack-dev-server --mode development"
我在package.json中的启动脚本如下:
"start": "webpack-dev-server --mode development"
But when I run npm start I get the bellow error: 但是当我运行npm start时,出现以下错误:
ERROR in Entry module not found: Error: Can't resolve './src'
在输入模块中找不到错误:错误:无法解析“ ./src”
. 。 I am on Windows 10. Could anybody explain what's wrong with my webpack config.
我在Windows 10上。有人可以解释我的Webpack配置有什么问题吗? I am specifying the entry file as
app/app.js
but still webpack is defaulting to src/index.js
. 我将入口文件指定为
app/app.js
但webpack仍默认为src/index.js
。
Thanks in advance. 提前致谢。
Just hand in your webpack config explicitely by changing your npm start
script to: 只需将npm
start
脚本更改为明确地上交Webpack配置:
"start": "webpack-dev-server --config webpackdev.babel.js"
Webpack searches for webpack.config.js
in the root folder automatically. Webpack
webpack.config.js
在根文件夹中自动搜索webpack.config.js
。 Starting with v4, Webpack also claims to be a zero config bundler, so it will use opinionated defaults , if no config can be located. 从v4开始,Webpack还声称自己是零配置捆绑器,因此,如果找不到任何配置,它将使用默认的默认值 。 Eg:
例如:
src/index
src/index
dist/main.js
dist/main.js
Your config seems to be right, but Webpack can't find it and assumes the default entry, thus your error Can't resolve './src'
. 您的配置似乎正确,但是Webpack找不到它并采用默认条目,因此您的错误
Can't resolve './src'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.