reactjs - next.config.js 中的@babel/preset-react 未使用 babel-loader 加载
问题描述
我的 webpack 没有正确转换我的 jsx(可能还有样式组件),所以我认为 babel 没有正确运行!我不确定是样式组件不起作用还是直接反应。
我收到SyntaxError: Unexpected token '<'
next.config.js
module.exports = withImages({
publicRuntimeConfig: {
...config,
},
webpack: (config, { isServer }) => {
config.plugins.push(
new CopyWebpackPlugin([
{
from: path.join(
__dirname,
process.env.ENV !== 'production'
? 'favicons/staging/favicon.ico'
: 'favicons/production/favicon.ico',
),
to: path.join(__dirname, 'public/favicon.ico'),
},
{
from: path.join(
__dirname,
process.env.ENV !== 'production'
? 'favicons/staging/favicon'
: 'favicons/production/favicon',
),
to: path.join(__dirname, 'public/favicon/'),
},
]),
)
config.module.rules.push({
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['next/babel', '@babel/preset-env', '@babel/preset-react'],
plugins: [
'babel-plugin-styled-components',
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-export-namespace-from",
[
"babel-plugin-root-import",
{
"paths": [
{
"rootPathPrefix": "~",
"rootPathSuffix": ""
}
]
}
],
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
],
},
},
],
})
return config
},
})
解决方案
推荐阅读
- javascript - 如何在网页加载时自动按 Tab 键
- c - 在嵌入式寄存器结构中用位移位替换位域
- coordinate-systems - 计算坐标系之间的关系
- javascript - 将数据更新到仪表针
- python - Python 子进程模块 | Postgres pg_dump 带密码
- c# - 从控制器配置连接字符串 (ASP.NET Core MVC 2.1)
- async-await - 如何将 showDialog 与等待一起使用
- immutable.js - 不可变的 mergeIn 覆盖原始值
- visual-studio-code - vscode:会话数据(恢复打开的文件)存储在哪里?可以使用相对路径吗?
- mongodb - 如何更新文档网络中数组中的字段