From afa697f95449bdedb919572301470cd27f9ec89a Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Tue, 24 Oct 2023 09:28:23 +0200 Subject: [PATCH] Build: Faster external plugin builds (#76974) * build(plugin-configs): move swc-loader to configs and use require.resolve for less duplicate deps * build(plugins): move cacheLocation to ESLintPlugin, run lint and tscheck plugins in dev * revert(plugins): remove obsolete stats setting --- packages/grafana-plugin-configs/package.json | 1 + .../grafana-plugin-configs/webpack.config.ts | 44 ++++++++++--------- .../grafana-testdata-datasource/package.json | 1 - yarn.lock | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/packages/grafana-plugin-configs/package.json b/packages/grafana-plugin-configs/package.json index cae7f3f444b..db5e3783f72 100644 --- a/packages/grafana-plugin-configs/package.json +++ b/packages/grafana-plugin-configs/package.json @@ -13,6 +13,7 @@ "fork-ts-checker-webpack-plugin": "8.0.0", "glob": "10.3.3", "replace-in-file-webpack-plugin": "1.0.6", + "swc-loader": "0.2.3", "webpack": "5.89.0" }, "packageManager": "yarn@3.6.0" diff --git a/packages/grafana-plugin-configs/webpack.config.ts b/packages/grafana-plugin-configs/webpack.config.ts index 315f4a34f07..7d5f7032524 100644 --- a/packages/grafana-plugin-configs/webpack.config.ts +++ b/packages/grafana-plugin-configs/webpack.config.ts @@ -3,7 +3,7 @@ import ESLintPlugin from 'eslint-webpack-plugin'; import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; import path from 'path'; import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin'; -import { Configuration } from 'webpack'; +import { Configuration, DefinePlugin } from 'webpack'; import { DIST_DIR } from './constants'; import { getPackageJson, getPluginJson, getEntries, hasLicense } from './utils'; @@ -29,12 +29,6 @@ const config = async (env: Record): Promise => { config: [__filename], }, cacheDirectory: path.resolve(__dirname, '../../.yarn/.cache/webpack', path.basename(process.cwd())), - cacheLocation: path.resolve( - __dirname, - '../../.yarn/.cache/eslint-webpack-plugin', - path.basename(process.cwd()), - '.eslintcache' - ), }, context: process.cwd(), @@ -89,7 +83,7 @@ const config = async (env: Record): Promise => { exclude: /(node_modules)/, test: /\.[tj]sx?$/, use: { - loader: 'swc-loader', + loader: require.resolve('swc-loader'), options: { jsc: { baseUrl: '.', @@ -186,21 +180,31 @@ const config = async (env: Record): Promise => { ], }, ]), - new ForkTsCheckerWebpackPlugin({ - async: Boolean(env.development), - issue: { - include: [{ file: '**/*.{ts,tsx}' }], - }, - typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') }, - }), - new ESLintPlugin({ - extensions: ['.ts', '.tsx'], - lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files - }), + env.development + ? new ForkTsCheckerWebpackPlugin({ + async: true, + issue: { + include: [{ file: '**/*.{ts,tsx}' }], + }, + typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') }, + }) + : new DefinePlugin({}), + env.development + ? new ESLintPlugin({ + extensions: ['.ts', '.tsx'], + lintDirtyModulesOnly: true, // don't lint on start, only lint changed files + cacheLocation: path.resolve( + __dirname, + '../../.yarn/.cache/eslint-webpack-plugin', + path.basename(process.cwd()), + '.eslintcache' + ), + }) + : new DefinePlugin({}), ], resolve: { - extensions: ['.js', '.jsx', '.ts', '.tsx'], + extensions: ['.ts', '.tsx', '.js', '.jsx'], unsafeCache: true, }, diff --git a/public/app/plugins/datasource/grafana-testdata-datasource/package.json b/public/app/plugins/datasource/grafana-testdata-datasource/package.json index 45c8bbf60ba..3f3e7d21458 100644 --- a/public/app/plugins/datasource/grafana-testdata-datasource/package.json +++ b/public/app/plugins/datasource/grafana-testdata-datasource/package.json @@ -26,7 +26,6 @@ "@types/node": "18.18.5", "@types/react": "18.2.15", "@types/testing-library__jest-dom": "5.14.8", - "swc-loader": "0.2.3", "ts-node": "10.9.1", "webpack": "5.89.0" }, diff --git a/yarn.lock b/yarn.lock index d0a3198a58e..8405e1e71ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2857,7 +2857,6 @@ __metadata: react: 18.2.0 react-use: 17.4.0 rxjs: 7.8.1 - swc-loader: 0.2.3 ts-node: 10.9.1 tslib: 2.6.0 webpack: 5.89.0 @@ -3255,6 +3254,7 @@ __metadata: fork-ts-checker-webpack-plugin: 8.0.0 glob: 10.3.3 replace-in-file-webpack-plugin: 1.0.6 + swc-loader: 0.2.3 tslib: 2.6.0 webpack: 5.89.0 languageName: unknown