我使用的是单一的.babelrc配置和使用它webpack.config.client.js,并webpack.config.server.js用巴贝尔装载机。
.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,react-hot-loader 发现它可以进入已编译的服务器代码。我做了一些研究,我看到 babel 7 允许为这种情况配置覆盖。
我试图实现它,但“env”部分永远不会被覆盖:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
},
"overrides": {
"include": "./src/server/index.js", // ?
"env": …Run Code Online (Sandbox Code Playgroud) 我正在尝试将自定义react组件发布到私有存储库。
我用来react-loadable按需加载子组件。在本地运行时,一切正常。必要时,index.js文件正确地向chunk.js文件发出请求。但是,当从另一个项目发布并使用该组件时,该组件在尝试请求子组件块时遇到404错误。编写库时,我应该如何拆分块并按需加载它们?这是否有可能或者我是否以错误的方式思考?
如果配置很简单,这是我的webpack.config.js:
module.exports = () => ({
context: __dirname,
mode: 'development',
entry: './src/index.jsx',
output: {
path: path.join(__dirname, './dist'),
filename: "index.js",
library: "reactcombobox",
libraryTarget: "umd",
publicPath: path.join(__dirname, './dist'),
umdNamedDefine: true
},
plugins: [
new webpack.LoaderOptionsPlugin({ options: { context: __dirname}}),
new CleanWebpackPlugin([path.join(__dirname, './dist')], {verbose: true, allowExternal: true})
],
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
"targets": {
"browsers": ["last 4 Chrome versions"]
}
}],
'@babel/preset-react'
],
plugins: …Run Code Online (Sandbox Code Playgroud) 我尝试将Redux与next.js入门项目一起使用,并安装next-redux-wrapper到该项目上,但不确定该项目中的根文件在哪里。
我尝试遵循next-redux-wrapper上显示的教程,但没有成功。没变化。
请帮助我如何将Redux添加到项目中。
问候。
javascript ×2
reactjs ×2
webpack ×2
babel-loader ×1
babeljs ×1
next.js ×1
npm ×1
publish ×1
redux ×1