mirror of
https://github.com/grafana/grafana.git
synced 2026-06-13 02:20:51 -04:00
* build(webpack): add tsconfig.json for Node strip-types compliance * build(webpack): extract shared esbuild options to esbuild.ts * build(webpack): add package.json to declare ESM module type * build(webpack): convert sass.rule to TypeScript * build(webpack): convert CorsWorkerPlugin to TypeScript * build(webpack): convert FeatureFlaggedSriPlugin to TypeScript * build(webpack): convert webpack.common to TypeScript, add theme entries * build(webpack): convert webpack.dev to TypeScript, remove esbuild duplication * build(webpack): convert webpack.prod to TypeScript, remove esbuild duplication * build(webpack): fix TypeScript types in webpack.prod transform callback * build(webpack): convert webpack.stats to TypeScript * build(webpack): update scripts to use TypeScript webpack configs * build(webpack): simplify env-util to use import.meta.dirname directly * build(webpack): tidy up plugins * build(webpack): move rules for ts and sass into single module * build(webpack): consolidate shared config into common, move splitChunks to prod - Move MiniCssExtractPlugin, esbuildRule and sassRule into common so both dev and prod configs share them without duplication - Move splitChunks/runtimeChunk optimisation to webpack.prod only (not needed in dev) - Use require() for SubresourceIntegrityPlugin to work around broken ESM build (waysact/webpack-subresource-integrity#236) - Refactor conditional plugin logic in dev from ternary to if-blocks * build(webpack): remove dead import and clarify webpack destructure pattern - Remove unused MiniCssExtractPlugin import from webpack.prod (moved to common) - Add comment explaining why DefinePlugin/EnvironmentPlugin are destructured from the default webpack import rather than using named ESM imports * style(webpack): reorder consts * chore(env-util): fix up env-util and webpack configs so tests continue to run * refactor(env-util): accept grafanaRoot param instead of relying on __dirname Removes the global.__dirname mutation hack in webpack.common.ts by making the grafana root path an explicit argument to getEnvConfig. Each caller resolves its own root and passes it in, removing the implicit path-depth contract and the CJS/ESM compatibility workaround. * build(webpack): remove unused angular chunk group
57 lines
2 KiB
TypeScript
57 lines
2 KiB
TypeScript
import webpack, { type Chunk, type Compilation, type Compiler } from 'webpack';
|
|
|
|
const { RuntimeGlobals, RuntimeModule } = webpack;
|
|
|
|
class CorsWorkerPublicPathRuntimeModule extends RuntimeModule {
|
|
publicPath: string;
|
|
|
|
constructor(publicPath: string) {
|
|
super('publicPath', RuntimeModule.STAGE_BASIC);
|
|
this.publicPath = publicPath;
|
|
}
|
|
|
|
generate(): string {
|
|
const { compilation, publicPath } = this;
|
|
|
|
const publicPathValue = compilation!.getPath(publicPath || '', {
|
|
hash: compilation!.hash || 'XXXX',
|
|
});
|
|
return `${RuntimeGlobals.publicPath} = __webpack_worker_public_path__ || '${publicPathValue}';`;
|
|
}
|
|
}
|
|
|
|
// https://github.com/webpack/webpack/discussions/14648#discussioncomment-1604202
|
|
// by @ https://github.com/piotr-oles
|
|
export default class CorsWorkerPlugin {
|
|
apply(compiler: Compiler): void {
|
|
compiler.hooks.compilation.tap('CorsWorkerPlugin', (compilation: Compilation) => {
|
|
const getChunkLoading = (chunk: Chunk) => {
|
|
const entryOptions = chunk.getEntryOptions();
|
|
return entryOptions && entryOptions.chunkLoading !== undefined
|
|
? entryOptions.chunkLoading
|
|
: compilation.outputOptions.chunkLoading;
|
|
};
|
|
const getChunkPublicPath = (chunk: Chunk) => {
|
|
const entryOptions = chunk.getEntryOptions();
|
|
return entryOptions && entryOptions.publicPath !== undefined
|
|
? entryOptions.publicPath
|
|
: compilation.outputOptions.publicPath;
|
|
};
|
|
|
|
compilation.hooks.runtimeRequirementInTree
|
|
.for(RuntimeGlobals.publicPath)
|
|
.tap('CorsWorkerPlugin', (chunk: Chunk) => {
|
|
if (getChunkLoading(chunk) === 'import-scripts') {
|
|
const publicPath = getChunkPublicPath(chunk);
|
|
|
|
if (publicPath !== 'auto') {
|
|
const module = new CorsWorkerPublicPathRuntimeModule(String(publicPath));
|
|
compilation.addRuntimeModule(chunk, module);
|
|
return true;
|
|
}
|
|
}
|
|
return undefined;
|
|
});
|
|
});
|
|
}
|
|
}
|