-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support the rspack multi plugin
feat: support the rspack multi plugin
- Loading branch information
Showing
19 changed files
with
263 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@rsdoctor/webpack-plugin': patch | ||
'@rsdoctor/rspack-plugin': patch | ||
'@rsdoctor/core': patch | ||
'@rsdoctor/sdk': patch | ||
--- | ||
|
||
feat(rspack): support the rspack multi plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import rspack from '@rspack/core'; | ||
import { resolve } from 'path'; | ||
const config = require('./rspack.config.js'); | ||
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh'); | ||
const { RsdoctorRspackMultiplePlugin } = require('@rsdoctor/rspack-plugin'); | ||
|
||
// console.log(config) | ||
|
||
function rspackBuild(config: rspack.Configuration) { | ||
return new Promise<void>((resolve) => { | ||
rspack.rspack(config, (err, stats) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log(); | ||
|
||
if (stats) { | ||
console.log( | ||
stats.toString({ | ||
chunks: false, | ||
chunkModules: false, | ||
colors: true, | ||
modules: false, | ||
children: false, | ||
}), | ||
); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
async function build() { | ||
await Promise.all([ | ||
rspackBuild({ | ||
...config, | ||
name: 'Builder 1', | ||
target: 'web', | ||
plugins: [ | ||
new ReactRefreshPlugin(), | ||
new RsdoctorRspackMultiplePlugin({ | ||
stage: 0, | ||
disableClientServer: false, | ||
features: ['bundle', 'plugins', 'loader'], | ||
}), | ||
new rspack.HtmlRspackPlugin({ | ||
template: './index.html', | ||
}), | ||
new rspack.CopyRspackPlugin({ | ||
patterns: [ | ||
{ | ||
from: 'public', | ||
}, | ||
], | ||
}), | ||
], | ||
}), | ||
rspackBuild({ | ||
...config, | ||
entry: './src/index.ts', | ||
mode: 'none', | ||
name: 'Builder 2', | ||
target: 'node', | ||
output: { | ||
path: resolve(__dirname, 'dist/node'), | ||
filename: 'index.js', | ||
}, | ||
plugins: [ | ||
new RsdoctorRspackMultiplePlugin({ | ||
stage: 1, | ||
disableClientServer: false, | ||
features: ['bundle', 'plugins', 'loader'], | ||
}), | ||
new rspack.CopyRspackPlugin({ | ||
patterns: [ | ||
{ | ||
from: 'public', | ||
}, | ||
], | ||
}), | ||
], | ||
}), | ||
]); | ||
} | ||
|
||
build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,17 @@ | ||
import React from 'react'; | ||
import logo from './logo.svg'; | ||
import Footer from './Footer'; | ||
import './App.css'; | ||
import { Button } from '@arco-design/web-react'; | ||
import '@arco-design/web-react/dist/css/arco.css'; | ||
import styles from './index.module.less'; | ||
|
||
function App() { | ||
export function App({ name }: any) { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
<Footer /> | ||
</div> | ||
<> | ||
Hello <i>{name}</i>. Welcome! | ||
<> | ||
<h1 className={styles.header}>标题{name}</h1> | ||
<p className="worker">内容</p> | ||
<Button type="primary">Hello Arco</Button>, | ||
</> | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { Button } from '@arco-design/web-react'; | ||
import '@arco-design/web-react/dist/css/arco.css'; | ||
import styles from './index.module.less'; | ||
|
||
export function App({ name }: any) { | ||
return ( | ||
<> | ||
Hello <i>{name}</i>. Welcome! | ||
<> | ||
<h1 className={styles.header}>标题{name}</h1> | ||
<p className="worker">内容</p> | ||
<Button type="primary">Hello Arco</Button>, | ||
</> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
declare module '*.svg' { | ||
const content: React.FunctionComponent<React.SVGAttributes<SVGElement>>; | ||
export default content; | ||
} | ||
|
||
declare module '*.less' { | ||
const classes: { [className: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*/settings.json' { | ||
const value: { | ||
colorWeek: boolean; | ||
navbar: boolean; | ||
menu: boolean; | ||
footer: boolean; | ||
themeColor: string; | ||
menuWidth: number; | ||
}; | ||
|
||
export default value; | ||
} | ||
|
||
declare module '*.png' { | ||
const value: string; | ||
export default value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.header { | ||
background: var(--color-bg-2); | ||
padding: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { render } from 'react-dom'; | ||
import { createElement } from 'react'; | ||
|
||
import { App } from './app1'; | ||
|
||
render( | ||
createElement(App, { name: 'Taylor' }), | ||
document.getElementById('root')!, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { RsdoctorWebpackSDK } from '@rsdoctor/sdk'; | ||
import { RsdoctorSlaveSDK, RsdoctorWebpackSDK } from '@rsdoctor/sdk'; | ||
|
||
let sdk: RsdoctorWebpackSDK; | ||
|
||
export function setSDK(t: RsdoctorWebpackSDK) { | ||
sdk = t; | ||
} | ||
|
||
export function getSDK(): RsdoctorWebpackSDK { | ||
export function getSDK(builderName?: string) { | ||
if (sdk && builderName && 'parent' in sdk) { | ||
const _sdk = sdk as unknown as RsdoctorSlaveSDK; | ||
const slaveSDK = _sdk.parent.slaves.find( | ||
(_sdk: { name: string }) => _sdk.name === builderName, | ||
); | ||
return slaveSDK || sdk; | ||
} | ||
return sdk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './plugin'; | ||
export * from './multiple'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { RsdoctorSDKController } from '@rsdoctor/sdk'; | ||
import type { Linter } from '@rsdoctor/types'; | ||
import type { RsdoctorMultiplePluginOptions } from '@rsdoctor/core'; | ||
|
||
import { RsdoctorRspackPlugin } from './plugin'; | ||
|
||
let globalController: RsdoctorSDKController | undefined; | ||
|
||
export class RsdoctorRspackMultiplePlugin< | ||
Rules extends Linter.ExtendRuleData[], | ||
> extends RsdoctorRspackPlugin<Rules> { | ||
// @ts-expect-error | ||
private controller: RsdoctorSDKController; | ||
|
||
constructor(options: RsdoctorMultiplePluginOptions<Rules> = {}) { | ||
const controller = (() => { | ||
if (globalController) { | ||
return globalController; | ||
} | ||
const controller = new RsdoctorSDKController(); | ||
globalController = controller; | ||
return controller; | ||
})(); | ||
|
||
const instance = controller.createSlave({ | ||
name: options.name || 'Builder', | ||
stage: options.stage, | ||
extraConfig: { disableTOSUpload: options.disableTOSUpload || false }, | ||
}); | ||
|
||
super({ | ||
...options, | ||
sdkInstance: instance, | ||
}); | ||
|
||
this.controller = controller; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.