Skip to content

Commit cfc1420

Browse files
committed
feat(create-plugin): update rspack config, bump to 1.2.4 for sri plugin
1 parent a084c11 commit cfc1420

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as webpack from 'webpack';
2+
3+
const PLUGIN_NAME = 'BuildModeRspackPlugin';
4+
5+
export class BuildModeRspackPlugin {
6+
apply(compiler: webpack.Compiler) {
7+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
8+
compilation.hooks.processAssets.tap(
9+
{
10+
name: PLUGIN_NAME,
11+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
12+
},
13+
assets => {
14+
for (const asset of assets) {
15+
if (asset.name.endsWith('plugin.json')) {
16+
const { RawSource } = compiler.webpack.sources;
17+
const pluginJsonContent = JSON.parse(asset.source());
18+
const pluginJsonWithBuildMode = JSON.stringify(
19+
{
20+
...pluginJsonContent,
21+
buildMode: compilation.options.mode,
22+
},
23+
null,
24+
4
25+
);
26+
const source = new RawSource(pluginJsonWithBuildMode);
27+
compilation.updateAsset(asset.name, source);
28+
}
29+
}
30+
}
31+
);
32+
});
33+
}
34+
}

packages/create-plugin/templates/common/.config/rspack/rspack.config.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
import rspack, { type Configuration } from '@rspack/core';
99
import ESLintPlugin from 'eslint-webpack-plugin';
10-
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
10+
import { TsCheckerRspackPlugin } from 'ts-checker-rspack-plugin';
1111
import path from 'path';
1212
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
1313
import TerserPlugin from 'terser-webpack-plugin';
1414
import { RspackVirtualModulePlugin } from 'rspack-plugin-virtual-module';
1515
import RspackLiveReloadPlugin from './liveReloadPlugin';
16-
16+
import { BuildModeRspackPlugin } from './BuildModeRspackPlugin';
1717
import { DIST_DIR, SOURCE_DIR } from './constants';
1818
import { getCPConfigVersion, getEntries, getPackageJson, getPluginJson, hasReadme, isWSL } from './utils';
1919

20+
const { SubresourceIntegrityPlugin } = rspack.experiments;
2021
const pluginJson = getPluginJson();
2122
const cpVersion = getCPConfigVersion();
2223

@@ -57,12 +58,15 @@ const config = async (env): Promise<Configuration> => {
5758
'react-redux',
5859
'redux',
5960
'rxjs',
60-
'react-router',
61+
'react-router',{{#unless useReactRouterV6}}
62+
'react-router-dom',{{/unless}}
6163
'd3',
62-
'angular',
63-
'@grafana/ui',
64+
'angular',{{#unless bundleGrafanaUI}}
65+
'@grafana/ui',{{/unless}}
6466
'@grafana/runtime',
65-
'@grafana/data',
67+
'@grafana/data',{{#if bundleGrafanaUI}}
68+
'react-inlinesvg',
69+
'i18next',{{/if}}
6670

6771
// Mark legacy SDK imports as external if their name starts with the "grafana/" prefix
6872
//@ts-ignore - rspack types seem to be a bit broken here.
@@ -167,16 +171,22 @@ const config = async (env): Promise<Configuration> => {
167171
},
168172

169173
output: {
174+
clean: {
175+
keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
176+
},
170177
filename: '[name].js',
178+
chunkFilename: env.production ? '[name].js?_cache=[contenthash]' : '[name].js',
171179
library: {
172180
type: 'amd',
173181
},
174182
path: path.resolve(process.cwd(), DIST_DIR),
175-
publicPath: `./`,
183+
publicPath: `public/plugins/${pluginJson.id}/`,
176184
uniqueName: pluginJson.id,
185+
crossOriginLoading: 'anonymous',
177186
},
178187

179188
plugins: [
189+
new BuildModeRspackPlugin(),
180190
virtualPublicPath,
181191
// Insert create plugin version information into the bundle
182192
new rspack.BannerPlugin({
@@ -223,10 +233,13 @@ const config = async (env): Promise<Configuration> => {
223233
],
224234
},
225235
]),
236+
new SubresourceIntegrityPlugin({
237+
hashFuncNames: ["sha256"],
238+
}),
226239
...(env.development
227240
? [
228241
new RspackLiveReloadPlugin(),
229-
new ForkTsCheckerWebpackPlugin({
242+
new TsCheckerRspackPlugin({
230243
async: Boolean(env.development),
231244
issue: {
232245
include: [{ file: '**/*.{ts,tsx}' }],
@@ -255,8 +268,6 @@ const config = async (env): Promise<Configuration> => {
255268
};
256269
}
257270

258-
259-
260271
return baseConfig;
261272
};
262273

packages/create-plugin/templates/common/_package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"@grafana/plugin-e2e": "^1.17.1",{{/if}}
2525
"@grafana/tsconfig": "^2.0.0",{{#if usePlaywright}}
2626
"@playwright/test": "^1.41.2",{{/if}}{{#if useExperimentalRspack}}
27-
"@rspack/core": "^1.0.0",
28-
"@rspack/cli": "^1.0.0",{{/if}}
27+
"@rspack/core": "^1.2.4",
28+
"@rspack/cli": "^1.2.4",{{/if}}
2929
"@stylistic/eslint-plugin-ts": "^2.9.0",
3030
"@swc/core": "^1.3.90",
3131
"@swc/helpers": "^0.5.0",
@@ -46,8 +46,8 @@
4646
"eslint-plugin-react": "^7.33.0",
4747
"eslint-plugin-react-hooks": "^4.6.0",
4848
"eslint-plugin-deprecation": "^2.0.0",
49-
"eslint-webpack-plugin": "^4.0.1",
50-
"fork-ts-checker-webpack-plugin": "^8.0.0",
49+
"eslint-webpack-plugin": "^4.0.1"{{#unless useExperimentalRspack}},
50+
"fork-ts-checker-webpack-plugin": "^8.0.0",{{/unless}}
5151
"glob": "^10.2.7",
5252
"identity-obj-proxy": "3.0.0",
5353
"imports-loader": "^5.0.0",
@@ -62,7 +62,8 @@
6262
"style-loader": "3.3.3",{{#unless useExperimentalRspack}}
6363
"swc-loader": "^0.2.3",{{/unless}}
6464
"terser-webpack-plugin": "^5.3.10",
65-
"ts-node": "^10.9.2",
65+
"ts-node": "^10.9.2",{{#if useExperimentalRspack}}
66+
"ts-checker-rspack-plugin": "^1.0.0",{{/if}}
6667
"typescript": "5.5.4",
6768
"webpack": "^5.94.0"{{#unless useExperimentalRspack}},
6869
"webpack-cli": "^5.1.4",

0 commit comments

Comments
 (0)