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

feat: webpack plugin #2699

Merged
merged 30 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ea31cbc
feat: 新增webapck插件
Sep 24, 2023
c4ccf55
feat: 新增webapck插件
nayonglin Sep 24, 2023
e4c4a84
feat: 完成qiankun插件,简化子应用改造难度
nayonglin Sep 25, 2023
15c8445
docs: update README.md for qiankun-plugin
nayonglin Sep 25, 2023
9612df1
fix: rename plugin to @qiankunjs/webpack-plugin
nayonglin Sep 25, 2023
aa39469
fix:Revert changes to globals.ts
nayonglin Sep 25, 2023
a8894df
refactor: migrate QiankunPlugin to TypeScript
nayonglin Sep 26, 2023
94bf900
docs: update examples
nayonglin Sep 26, 2023
7e24ee7
fix: change libraryTarget to window
nayonglin Sep 26, 2023
5413104
feat: feat: plugin add automatic 'entry' attribute addition to main s…
nayonglin Sep 27, 2023
8ccbfbb
refactor: rename qiankun plugin directory to webpack-plugin
nayonglin Sep 28, 2023
86a349d
fix: delete new pluginDemo
nayonglin Oct 7, 2023
d37111e
fix: change plugin to esm
nayonglin Oct 8, 2023
4284143
docs: add comment to plugin
nayonglin Oct 8, 2023
1d95b5a
fix: eslint to plugin
nayonglin Oct 8, 2023
92cf01d
feat: add English documentation for @qiankunjs/webpack-plugin
nayonglin Oct 11, 2023
a1f2c81
feat(tests): add automated test cases for QiankunPlugin
nayonglin Oct 19, 2023
5760f84
feat(tests): add automated test cases for QiankunPlugin
nayonglin Oct 19, 2023
24ba3c2
Merge branch 'next' into feat/webpack_plugin
kuitos Oct 23, 2023
eb97056
chore(deps): update pnpm lockfile
nayonglin Oct 23, 2023
ca4f1e8
chore(deps): update pnpm lockfile
nayonglin Oct 23, 2023
070295f
chore: update lockfile
aladdin-add Oct 24, 2023
87c8293
Merge remote-tracking branch 'upstream/next' into feat/webpack_plugin
nayonglin Oct 27, 2023
06da38d
Create modern-kiwis-tap.md
kuitos Oct 27, 2023
82a1c22
fix: eslint for plugin
nayonglin Oct 27, 2023
a3b3c9d
fix: prettier for plugin
nayonglin Oct 27, 2023
aa38e16
chore: update build cmd
nayonglin Oct 29, 2023
8852c46
Update package.json
kuitos Oct 30, 2023
d06d26b
Update package.json
kuitos Oct 30, 2023
996f340
Update package.json
kuitos Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ <h1>QianKun</h1>
</header>
<div class="mainapp-main">
<!-- 侧边栏 -->
<ul class="mainapp-sidemenu">
<ul class="mainapp-sidemenu">
<li data-value='react16'>React16</li>
<li data-value='react15'>React15</li>
<li data-value='react16-plugin'>React16-plugin</li>
<li data-value='react15-plugin'>React15-plugin</li>
</ul>
<!-- 子应用 -->
<main id="subapp-container"></main>
Expand Down
2 changes: 2 additions & 0 deletions examples/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import './index.less';
const microApps = [
{ name: 'react15', entry: '//localhost:7102' },
{ name: 'react16', entry: '//localhost:7100' },
{ name: 'react15-plugin', entry: '//localhost:7103' },
{ name: 'react16-plugin', entry: '//localhost:7100' },
];

let prevApp;
Expand Down
35 changes: 35 additions & 0 deletions examples/react15-plugin/App.jsx
nayonglin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { version as reactVersion } from 'react';
import { version as antdVersion } from 'antd';

import Logo from './components/Logo';
import HelloModal from './components/HelloModal';

export default class App extends React.Component {
componentDidMount() {
const now = Date.now();
const during = now - (window.startTime || performance.timing.navigationStart);
const mount = now - window.evalStart;
console.log('render during', during);
this.setState({ during, mount });
}

render() {
const { during, mount } = this.state || {};

return (
<div className="react15-main">
<Logo />
{during ? (
<b>
qiankun rendering cost {during} ms {window.useRuntimeDeps ? 'with' : 'without'} runtime deps reused
</b>
) : null}
<b>app self rendering cost {mount} ms</b>
<p className="react15-lib">
React version: {reactVersion}, antd version: {antdVersion}
</p>
<HelloModal />
</div>
);
}
}
34 changes: 34 additions & 0 deletions examples/react15-plugin/components/HelloModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { Button, Modal } from 'antd';

export default class HelloModal extends React.Component {

constructor() {
super();
this.state = {
visible: false,
};
this.setVisible = visible => this.setState({ visible });
}

render() {
const { visible } = this.state;

return (
<div>
<Button onClick={() => this.setVisible(true)}>
CLICK ME
</Button>
<Modal
visible={visible}
closable={false}
onOk={() => this.setVisible(false)}
onCancel={() => this.setVisible(false)}
title="Install"
>
<code>$ yarn add qiankun # or npm i qiankun -S</code>
</Modal>
</div>
);
}
}
12 changes: 12 additions & 0 deletions examples/react15-plugin/components/Logo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export default class ReactLogo extends React.Component {
render() {
return (
<img
className="react15-icon"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0xMS41IC0xMC4yMzE3NCAyMyAyMC40NjM0OCI+CiAgPHRpdGxlPlJlYWN0IExvZ288L3RpdGxlPgogIDxjaXJjbGUgY3g9IjAiIGN5PSIwIiByPSIyLjA1IiBmaWxsPSIjNjFkYWZiIi8+CiAgPGcgc3Ryb2tlPSIjNjFkYWZiIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiPgogICAgPGVsbGlwc2Ugcng9IjExIiByeT0iNC4yIi8+CiAgICA8ZWxsaXBzZSByeD0iMTEiIHJ5PSI0LjIiIHRyYW5zZm9ybT0icm90YXRlKDYwKSIvPgogICAgPGVsbGlwc2Ugcng9IjExIiByeT0iNC4yIiB0cmFuc2Zvcm09InJvdGF0ZSgxMjApIi8+CiAgPC9nPgo8L3N2Zz4K"
/>
)
}
}
5 changes: 5 additions & 0 deletions examples/react15-plugin/dynamic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* 动态加载的样式 */

.react15-lib {
color: #818ff7;
}
15 changes: 15 additions & 0 deletions examples/react15-plugin/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.react15-main {
display: flex;
flex-direction: column;
align-items: center;
}

.react15-icon {
width: 140px;
}

.react15-lib {
margin: 32px 0 24px;
font-size: 16px;
color: #2c3e50;
}
39 changes: 39 additions & 0 deletions examples/react15-plugin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Title</title>
<script>window.evalStart = Date.now();</script>
<script>window.useRuntimeDeps = true;</script>
<script type="dependencymap">
{
"dependencies": {
"antd": {
"url": "https://gw.alipayobjects.com/os/lib/antd/2.12.2/dist/antd.js",
"version": "2.12.2",
"range": "^2.12.2"
},
"react": {
"url": "https://gw.alipayobjects.com/os/lib/react/15.6.2/dist/react.js",
"version": "15.6.2",
"range": "^15.6.2"
},
"react-dom": {
"url": "https://gw.alipayobjects.com/os/lib/react-dom/15.6.2/dist/react-dom.js",
"version": "15.6.2",
"range": "^15.6.2"
}
}
}
</script>
<script src="https://gw.alipayobjects.com/os/lib/react/15.6.2/dist/react.js"></script>
<script src="https://gw.alipayobjects.com/os/lib/react-dom/15.6.2/dist/react-dom.js"></script>
<script src="https://gw.alipayobjects.com/os/lib/antd/2.12.2/dist/antd.js"></script>
</head>

<body>
<div id="react15Root"></div>
</body>

</html>
45 changes: 45 additions & 0 deletions examples/react15-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @author Kuitos
* @since 2019-05-16
*/
import 'antd/dist/antd.min.css';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import './public-path';

export async function bootstrap() {
console.log('[react15] react app bootstraped');
}

export async function mount(props = {}) {
console.log('[react15] props from main framework', props);
const { container } = props;
ReactDOM.render(
<App />,
container ? container.querySelector('#react15Root') : document.getElementById('react15Root'),
);
import('./dynamic.css').then(() => {
console.log('[react15] dynamic style load');
});

const styleElement = document.createElement('style');
styleElement.innerText = '.react15-icon { height: 400px }';
document.head.appendChild(styleElement);

setTimeout(() => {
document.head.removeChild(styleElement);
}, 2000);
}

export async function unmount(props) {
const { container } = props;
ReactDOM.unmountComponentAtNode(
container ? container.querySelector('#react15Root') : document.getElementById('react15Root'),
);
}

if (!window.__POWERED_BY_QIANKUN__) {
bootstrap().then(mount);
}
31 changes: 31 additions & 0 deletions examples/react15-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "react15-plugin",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"dependencies": {
"antd": "2.13.14",
"react": "15.6.2",
"react-dom": "15.6.2"
},
"devDependencies": {
"@babel/core": "^7.7.2",
"@babel/plugin-transform-react-jsx": "^7.7.0",
"@babel/preset-env": "^7.7.1",
"babel-loader": "^8.0.6",
"css-loader": "^3.2.0",
"html-webpack-plugin": "^3.2.0",
"style-loader": "^1.0.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
},
"browserslist": [
"last 2 Chrome versions"
]
}
3 changes: 3 additions & 0 deletions examples/react15-plugin/public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (window.__POWERED_BY_QIANKUN__) {
__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}
57 changes: 57 additions & 0 deletions examples/react15-plugin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const QiankunPlugin = require('@qiankunjs/webpack-plugin');


module.exports = {
entry: './index.js',
devtool: 'source-map',
devServer: {
port: '7103',
clientLogLevel: 'warning',
disableHostCheck: true,
compress: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
overlay: { warnings: false, errors: true },
},
mode: 'development',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-react-jsx'],
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
},
}),
new QiankunPlugin(),
],
externals: {
react: 'React',
'react-dom': 'ReactDOM',
antd: 'antd',
},
};
4 changes: 4 additions & 0 deletions examples/react16-plugin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SKIP_PREFLIGHT_CHECK=true
BROWSER=none
PORT=7100
WDS_SOCKET_PORT=7100
22 changes: 22 additions & 0 deletions examples/react16-plugin/.rescriptsrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const QiankunPlugin = require('@qiankunjs/webpack-plugin');

module.exports = {
webpack: config => {
config.plugins.push(new QiankunPlugin());
return config;
},
devServer: _ => {
const config = _;

config.headers = {
'Access-Control-Allow-Origin': '*',
};
config.historyApiFallback = true;

config.hot = false;
config.watchContentBase = false;
config.liveReload = false;

return config;
},
};
63 changes: 63 additions & 0 deletions examples/react16-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.<br /> Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br /> You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br /> See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.<br /> It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br /> Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
Loading