我正在努力将Webpack从2.7.0版更新到4.40.2版。这些是错误:
webpack is watching the files…
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
Version: webpack 4.40.2
Time: 42ms
Built at: 2019-09-16 12:34:56
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\myUIproject\'
Process terminated with code 0.
将--mode=development
遗漏的警告留给我,以前使用的Webpack.config.js
(参见下文)不再起作用:Can't resolve './src'
。
在Can't resolve './src'上已经有一个Stackoverflow帖子,给出的解决方案是完全删除webpack配置文件,而要使用类似这样的东西:
webpack ./src/index.tsx --output ./dist/bundle.js --mode development
我将其调整为我的体系结构(希望如此),但是出现以下错误,这意味着我没有这样做:
Version: webpack 4.40.2
Time: 42ms
Built at: 2019-09-16 12:34:56
Asset Size Chunks Chunk Names
bundle.js 4.13 KiB main [emitted] main
Entrypoint main = bundle.js
[./src/index.tsx] 350 bytes {main} [built] [failed] [1 error]
ERROR in ./src/index.tsx 51:4
Module parse failed: Unexpected token (51:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| ReactDOM.render(
> <LocaleProvider locale={enUS}>
| <Provider store={store}>
| <Layout>
请帮助我如何正确定义入口点?
我为Webpack 2.7.0工作的Webpack.config.js
如下
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: {
"bundle": ["babel-polyfill", "whatwg-fetch", "./src/index.tsx"]
},
output: {
filename: "[name].js",
path: __dirname + "/dist"
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
loaders: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, use: [
{
loader: 'babel-loader',
options: {
presets: [[
'env',
{
"targets": {
"browsers": ["ie >= 11"]
}
}
]]
}
},"ts-loader"] },
{ test: /\.js$/, loader: "source-map-loader" },
{ test: /\.less$/, loader: ExtractTextPlugin.extract("css-loader!less-loader") }
]
},
plugins: [
new ExtractTextPlugin("[name].css")
]
};
答案 0 :(得分:1)
您是否尝试将其更新为module.rules
而不是module.loaders
?
例如:
module.exports = {
module: {
rules: [
{ test: /\.css$/, use: 'css-loader' },
{ test: /\.ts$/, use: 'ts-loader' }
]
}
};
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, use: [
{
loader: 'babel-loader',
options: {
presets: [[
'env',
{
"targets": {
"browsers": ["ie >= 11"]
}
}
]]
}
},"ts-loader"] },
{ test: /\.js$/, loader: "source-map-loader" },
{ test: /\.less$/, loader: ExtractTextPlugin.extract("css-loader!less-loader") }
]
}