Skip to content

Commit

Permalink
feat: provider plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
HomyeeKing committed Jan 14, 2025
1 parent 91af2b5 commit 87dc343
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/ice/src/service/webpackServerCompiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const _dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fil

export class WebpackServerCompiler {
private config: webpack.Configuration;
private options: Record<string, any>;

constructor(options: any) {
this.options = options;
this.config = this.createWebpackConfig(options);
}
private createWebpackConfig(options: any): webpack.Configuration {
Expand Down Expand Up @@ -101,17 +103,27 @@ export class WebpackServerCompiler {
filename: '[file].map',
moduleFilenameTemplate: '[absolute-resource-path]',
}),
// new webpack.ProvidePlugin({
// 'window.jQuery': 'jquery',
// }),
],
stats: {
errorDetails: true,
},
};
}

private async handleEsbuildInject() {
const provideRecord = {};
const allInjects = await Promise.all(this.options.inject.map((inj) => import(inj)));
allInjects.forEach((injs, index) => {
Object.keys(injs).forEach((key) => {
provideRecord[key] = [this.options.inject[index], key];
});
});
return new webpack.ProvidePlugin(provideRecord);
}

async build(): Promise<any> {
const providePlugin = await this.handleEsbuildInject();
this.config.plugins.push(providePlugin);
return new Promise((resolve, reject) => {
webpack(this.config, (err, stats) => {
if (err || stats?.hasErrors?.()) {
Expand Down

0 comments on commit 87dc343

Please sign in to comment.