如何配置纯JS entry和JSX entry并存 #2383
Answered
by
SoonIter
congxiaobai
asked this question in
Q&A
-
我有一个项目,其中既包含了一个react 项目的entry。 如果这样配置,会默认添加一个 background的html,同时把其中的依赖分成了多个chunk,使得background.js打包后也无法独立在node中运行。 如果配置tools.htmlPlugin 为false。则index的html中不会被注入script引用,同时,打出来的包background.js 也无法独立运行。 具体看看这个Demo https://github.com/congxiaobai/rsbuildConfig |
Beta Was this translation helpful? Give feedback.
Answered by
SoonIter
May 19, 2024
Replies: 1 comment
-
可以看这篇文档,打包多平台的产物 https://rsbuild.dev/zh/config/source/entry#%E5%87%BD%E6%95%B0%E7%94%A8%E6%B3%95 import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
const templates = {
index: './public/index.html',
};
export default defineConfig({
plugins: [pluginReact()],
source: {
entry({ target }) {
if (target === 'web') {
return {
index: './src/index.jsx',
};
}
if (target === 'node') {
return {
background: './src/background.js',
};
}
},
},
html: {
inject: 'body',
template({ entryName }) {
return templates[entryName];
},
},
tools: {
htmlPlugin: false,
// htmlPlugin(config, { entryName, entryValue }) {
// if (entryName === 'background') {
// config.inject = false
// }
// },
},
output: {
filenameHash: false,
legalComments: 'none',
distPath: {
js: './',
css: './',
},
targets: ['web', 'node'],
// sourceMap: {
// js: 'source-map',
// },
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
congxiaobai
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以看这篇文档,打包多平台的产物
https://rsbuild.dev/zh/config/source/entry#%E5%87%BD%E6%95%B0%E7%94%A8%E6%B3%95