Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

目前只能用parcel吗,如果我想我webpack该怎么配置 #8

Closed
zeihang opened this issue Jun 25, 2019 · 13 comments
Closed

目前只能用parcel吗,如果我想我webpack该怎么配置 #8

zeihang opened this issue Jun 25, 2019 · 13 comments
Labels
question Further information is requested

Comments

@zeihang
Copy link

zeihang commented Jun 25, 2019

No description provided.

@kuitos
Copy link
Member

kuitos commented Jun 25, 2019

output libraryTarget 设置成 umd
https://webpack.js.org/configuration/output/#outputlibrarytarget

@kuitos kuitos added the question Further information is requested label Jun 25, 2019
@kuitos kuitos mentioned this issue Jun 26, 2019
@jiachaosun
Copy link

jiachaosun commented Jun 26, 2019

@kuitos
谢谢回复,我在output中加入了libraryTarget: "umd" ,然后用devServer方式启动,可是在main项目里点击后还是报相同的错误。

sub-app webpack config:

  output: {
    path: path.join(__dirname, "..", "dist"),
    chunkFilename: "[name].js",
    filename: "[name].js",
    publicPath: "",
    libraryTarget: "umd"
  },

sub-app index.js 也很简单

import React from "react";
import ReactDOM from "react-dom";

const App = () => <div>app</div>;

export async function bootstrap() {
  console.log("give web bootstraped");
}

export async function mount(props) {
  console.log("props from main framework", props);
  ReactDOM.render(<App />, document.getElementById("root"));
}

export async function unmount() {
  ReactDOM.unmountComponentAtNode(document.getElementById("root"));
}

错误信息:

index.js:56 Uncaught xxx web: Application 'xxx web' died in status LOADING_SOURCE_CODE: You need to export the functional lifecycles in xxx web entry

@zeihang
Copy link
Author

zeihang commented Jun 26, 2019

我是这么配置的

output: {
        filename: 'bundle.js',
        path: path.join(__dirname, './dist'),
        publicPath: '/',
        library: 'reactTs',
        libraryTarget: 'umd',
        umdNamedDefine: true
},

现在项目运行正常 @jiachaosun

@zeihang
Copy link
Author

zeihang commented Jun 26, 2019

是因为我用typescript的缘故吗,我跑普通react项目还是会报错

@jiachaosun
Copy link

@zeihang
我用了你的配置后,确实跑成功了。不过只能是子项目每次yarn start后的第一次,一旦hot reload触发一次后容器项目就还是上面那种报错。

PS:回复内容时,你可以使用md格式贴代码哦,这样看起来舒服。

@kuitos
Copy link
Member

kuitos commented Jun 26, 2019

{
  libraryTarget: 'umd',
  library: packageName,
  jsonpFunction: `webpackJsonp_${packageName}`
}

确保 webpack 有以上三个配置

@kuitos
Copy link
Member

kuitos commented Jun 26, 2019

updated README, see https://github.com/umijs/qiankun#webpack

@jiachaosun
Copy link

thx,@kuitos
现在已经运行成功,我的sub app非常复杂是一个50个页面app的web版。但是sub app一旦hot reload一次后,就还是会报这个错,无论是修改css还是js

index.js:56 Uncaught xxx web: Application 'xxx web' died in status LOADING_SOURCE_CODE: You need to export the functional lifecycles in xxx web entry

我猜测应该还是打包或者导出的问题,是否会和code split的格式有关系

@zeihang
Copy link
Author

zeihang commented Jun 26, 2019

@
跳子项目路由时没问题吗,我一跳转就会进入空白页面,热更新就没生效过

@jiachaosun
Copy link

@
跳子项目路由时没问题吗,我一跳转就会进入空白页面,热更新就没生效过

子项目路由跳转没问题,空白的问题应该是你子项目路由router没加basename吧

@kuitos kuitos closed this as completed Aug 14, 2019
@guojingwen
Copy link

guojingwen commented Sep 9, 2019

@kuitos 使用webpack构建,开发没有问题,打包后 子项目js 加载正常但不会运行,也没有报错,

@Measy
Copy link

Measy commented Mar 22, 2021

{
  libraryTarget: 'umd',
  library: packageName,
  jsonpFunction: `webpackJsonp_${packageName}`
}

确保 webpack 有以上三个配置

jsonpFunction在webpack5中不存在这个配置 会有问题吗? @kuitos

@jeremy-ww
Copy link

{
  libraryTarget: 'umd',
  library: packageName,
  jsonpFunction: `webpackJsonp_${packageName}`
}

确保 webpack 有以上三个配置

jsonpFunction在webpack5中不存在这个配置 会有问题吗? @kuitos

webpack5 是自动生成的,https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-unique-naming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants