gpt4 book ai didi

reactjs - 汇总,TypeScript,Electron,React设置

转载 作者:行者123 更新时间:2023-12-03 12:32:46 25 4
gpt4 key购买 nike

我正在尝试为 Electron 创建汇总设置,并使用 typescript 进行 react 。我收到未在/node_modules/react/index.js中定义的process的引用错误。
我创建了以下配置文件:
从'@ rollup/plugin-commonjs'导入commonjs
从“rollup-plugin-copy”导入副本
从'@ rollup/plugin-typescript'导入 typescript
从'@ rollup/plugin-node-resolve'导入{nodeResolve}
rollup-config.js:

export default [
// electron
{
input: 'src/main.ts',
output: [
{
file: 'build/main.js',
format: 'cjs',
sourcemap: true
},
],
plugins: [
nodeResolve(),
typescript({
target: 'es5',
}),
commonjs({
include: './node_modules/**',
}),
copy({
targets: [
{ src: './src/index.html', dest: './build' }
]
}),
]
},
// react
{
input: 'src/react/index.tsx',
output: [
{
file: 'build/scripts.js',
format: 'esm',
sourcemap: true,
globals: [
'react',
],
},
],
plugins: [
typescript({
target: 'es5',
module: 'ESNext',
}),
nodeResolve(),
commonjs({
include: './node_modules/**',
}),
]
}
]
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"dom",
"es2015",
"es2016",
"es2017"
],
"allowJs": true,
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"strict": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"esModuleInterop": true,
"jsx": "react",
},
"exclude": [
"node_modules"
]
}
希望您能帮到我。可悲的是我无法弄清楚问题出在哪里。
问候

最佳答案

我摆弄了一下,并按照我想要的方式进行了工作:
rollup.config.js

import commonjs from '@rollup/plugin-commonjs'
import copy from 'rollup-plugin-copy'
import typescript from '@rollup/plugin-typescript'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'

export default [
// electron
{
input: 'src/main.ts',
output: [
{
file: 'build/main.js',
format: 'cjs',
sourcemap: true
},
],
plugins: [
nodeResolve(),
typescript(),
commonjs({
include: './node_modules/**',
}),
copy({
targets: [
{ src: './src/index.html', dest: './build' }
]
}),
]
},
// react
{
input: 'src/react/index.tsx',
output: [
{
file: 'build/scripts.js',
format: 'esm',
sourcemap: true,
globals: [
'react',
],
},
],
plugins: [
typescript({
module: 'ESNext',
}),
commonjs({
include: './node_modules/**',
}),
nodeResolve(),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
]
}
]
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"dom",
"es2015",
"es2016",
"es2017"
],
"allowJs": true,
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"strict": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"esModuleInterop": true,
"jsx": "react",
},
"exclude": [
"node_modules"
]
}

关于reactjs - 汇总,TypeScript,Electron,React设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64047166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com