mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Build: Setup webpack configuration for direct-input bundled datasource (#67199)
This commit is contained in:
1
plugins-bundled/internal/input-datasource/.gitignore
vendored
Normal file
1
plugins-bundled/internal/input-datasource/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.yarn
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = {};
|
||||
@@ -1,8 +1,18 @@
|
||||
// This file is needed because it is used by vscode and other tools that
|
||||
// call `jest` directly. However, unless you are doing anything special
|
||||
// do not edit this file
|
||||
|
||||
const standard = require('@grafana/toolkit/src/config/jest.plugin.config');
|
||||
|
||||
// This process will use the same config that `yarn test` is using
|
||||
module.exports = standard.jestConfig();
|
||||
module.exports = {
|
||||
testEnvironment: 'jest-environment-jsdom',
|
||||
preset: 'ts-jest',
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
transform: {
|
||||
'^.+\\.(t|j)sx?$': [
|
||||
'ts-jest',
|
||||
{
|
||||
useESM: true,
|
||||
isolatedModules: true,
|
||||
allowJs: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'^d3-interpolate$': '<rootDir>/__mocks__/d3-interpolate.ts',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,27 +8,28 @@
|
||||
"url": "http://github.com/grafana/grafana.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "grafana-toolkit plugin:build",
|
||||
"test": "grafana-toolkit plugin:test",
|
||||
"dev": "grafana-toolkit plugin:dev",
|
||||
"watch": "grafana-toolkit plugin:dev --watch"
|
||||
"build": "yarn test && webpack -c webpack.config.ts --env production",
|
||||
"dev": "webpack -w -c webpack.config.ts --env development",
|
||||
"test": "jest -c jest.config.js"
|
||||
},
|
||||
"author": "Grafana Labs",
|
||||
"devDependencies": {
|
||||
"@grafana/toolkit": "10.0.0-pre",
|
||||
"@types/jest": "26.0.15",
|
||||
"@types/lodash": "4.14.149",
|
||||
"@types/react": "18.0.28",
|
||||
"lodash": "4.17.21"
|
||||
"copy-webpack-plugin": "11.0.0",
|
||||
"eslint-webpack-plugin": "4.0.0",
|
||||
"fork-ts-checker-webpack-plugin": "8.0.0",
|
||||
"jest": "29.3.1",
|
||||
"jest-environment-jsdom": "29.3.1",
|
||||
"ts-jest": "29.0.5",
|
||||
"ts-loader": "9.3.1",
|
||||
"ts-node": "10.9.1",
|
||||
"webpack": "5.76.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grafana/data": "10.0.0-pre",
|
||||
"@grafana/ui": "10.0.0-pre",
|
||||
"jquery": "3.5.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-hook-form": "7.5.3",
|
||||
"react-router-dom": "5.3.3",
|
||||
"tslib": "2.4.0"
|
||||
"tslib": "2.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,13 @@
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"baseUrl": "./src"
|
||||
},
|
||||
"ts-node": {
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"transpileOnly": true
|
||||
}
|
||||
}
|
||||
|
||||
146
plugins-bundled/internal/input-datasource/webpack.config.ts
Normal file
146
plugins-bundled/internal/input-datasource/webpack.config.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||
import ESLintPlugin from 'eslint-webpack-plugin';
|
||||
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
||||
import path from 'path';
|
||||
import { Configuration } from 'webpack';
|
||||
|
||||
const SOURCE_DIR = path.resolve(__dirname, 'src');
|
||||
const DIST_DIR = path.resolve(__dirname, 'dist');
|
||||
const PLUGIN_ID = require(path.join(SOURCE_DIR, 'plugin.json')).id;
|
||||
|
||||
const config = async (env: Record<string, string>): Promise<Configuration> => ({
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
buildDependencies: {
|
||||
config: [__filename],
|
||||
},
|
||||
},
|
||||
|
||||
context: path.join(process.cwd(), SOURCE_DIR),
|
||||
|
||||
devtool: env.production ? 'source-map' : 'eval-source-map',
|
||||
|
||||
entry: {
|
||||
module: path.join(SOURCE_DIR, 'module.ts'),
|
||||
},
|
||||
|
||||
externals: [
|
||||
'lodash',
|
||||
'jquery',
|
||||
'moment',
|
||||
'slate',
|
||||
'emotion',
|
||||
'@emotion/react',
|
||||
'@emotion/css',
|
||||
'prismjs',
|
||||
'slate-plain-serializer',
|
||||
'@grafana/slate-react',
|
||||
'react',
|
||||
'react-dom',
|
||||
'react-redux',
|
||||
'redux',
|
||||
'rxjs',
|
||||
'react-router',
|
||||
'react-router-dom',
|
||||
'd3',
|
||||
'angular',
|
||||
'@grafana/ui',
|
||||
'@grafana/runtime',
|
||||
'@grafana/data',
|
||||
|
||||
// Mark legacy SDK imports as external if their name starts with the "grafana/" prefix
|
||||
({ request }, callback) => {
|
||||
const prefix = 'grafana/';
|
||||
const hasPrefix = (request: string) => request.indexOf(prefix) === 0;
|
||||
const stripPrefix = (request: string) => request.substring(prefix.length);
|
||||
|
||||
if (request && hasPrefix(request)) {
|
||||
return callback(undefined, stripPrefix(request));
|
||||
}
|
||||
|
||||
callback();
|
||||
},
|
||||
],
|
||||
|
||||
mode: env.production ? 'production' : 'development',
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
exclude: /(node_modules)/,
|
||||
test: /\.[tj]sx?$/,
|
||||
use: {
|
||||
loader: 'ts-loader',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)$/,
|
||||
type: 'asset/resource',
|
||||
generator: {
|
||||
// Keep publicPath relative for host.com/grafana/ deployments
|
||||
publicPath: `public/plugins/${PLUGIN_ID}/img/`,
|
||||
outputPath: 'img/',
|
||||
filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
|
||||
type: 'asset/resource',
|
||||
generator: {
|
||||
// Keep publicPath relative for host.com/grafana/ deployments
|
||||
publicPath: `public/plugins/${PLUGIN_ID}/fonts`,
|
||||
outputPath: 'fonts/',
|
||||
filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
output: {
|
||||
clean: {
|
||||
keep: new RegExp(`.*?_(amd64|arm(64)?)(.exe)?`),
|
||||
},
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
type: 'amd',
|
||||
},
|
||||
path: DIST_DIR,
|
||||
publicPath: '/',
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{ from: '../README.md', to: '.', force: true, context: SOURCE_DIR },
|
||||
{ from: 'plugin.json', to: '.', context: SOURCE_DIR },
|
||||
{ from: '**/*.json', to: '.', context: SOURCE_DIR },
|
||||
{ from: '**/*.svg', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
{ from: '**/*.png', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
{ from: '**/*.html', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
{ from: 'img/**/*', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
{ from: 'static/**/*', to: '.', noErrorOnMissing: true, context: SOURCE_DIR }, // Optional
|
||||
],
|
||||
}),
|
||||
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
|
||||
}),
|
||||
],
|
||||
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
// handle resolving "rootDir" paths
|
||||
modules: [path.resolve(process.cwd(), 'src'), 'node_modules'],
|
||||
unsafeCache: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default config;
|
||||
Reference in New Issue
Block a user