* build(frontend): enable custom condition for resolving source files during dev and build * feat(packages): apply conditional name to export properties * chore(packages): add standard exports to flamegraph and prometheus * chore(packages): resolve main, module, types to built files * build(packages): clean up prepare-npm-package for custom condition changes * refactor(packages): reduce repetition in conditional exports * build(storybook): add @grafana-app/source to conditionNames * test(frontend): add grafana-app/source customCondition for jest tests * refactor(frontend): remove nested package import paths * chore(jest): use customExportConditions for source files and browser * chore(i18n): use src for ./eslint-plugin export * chore(packages): set packages tsconfigs to moduleResolution bundler * chore(packages): fix rollup builds * build(packages): build cjs as multiple files * chore(sql): reference MonitoringLogger for moduleresolution bundler to pass typecheck * chore(ui): add type refs for moduleresolution bundler to pass typecheck * feat(schema): add exports for cleaner import paths * refactor(frontend): clean up schema paths to point to exports instead of nested file paths * build(storybook): hack the builder-manager for custom conditions to resolve * build(decoupled-plugins): fix broken builds due to missing conditionNames * chore(e2e): pass condition to playwright to resolve local packages * build(frontend): fix failing build * chore(select): fix typings * style(frontend): clean up eslint suppressions * chore(packages): fix type errors due to incorrect tsconfig settings * build(generate-apis): use swc with ts-node and moduleResolution bundler * chore(cypress): add conditionNames to resolve monorepo packages * build(npm): update prepare to work with latest exports changes * build(packages): fix prepare-npm-package script * fix(e2e-selectors): update debugoverlay for data-testid change * build(packages): stop editing package.json at pack n publish time * rerun ci * chore(api-clients): use moduleResolution: bundler for customConditions support * chore(api-clients): fix generation * build(packages): remove aliasing exports, remove exports with only customConditions * Revert "refactor(frontend): clean up schema paths to point to exports instead of nested file paths" This reverts commit 7949b6ea0e60e51989d2a8149b7a24647cd68916. * revert(schema): remove exports from package so builds work * build(api-clients): fix up api-clients exports and rollup config * build(api-clients): Update generated package exports for api clients * build(schema): add overrides to cjsOutput and esmOutput so built directory structure is correct * fix(packages): use rootDirs to prevent types/src directories in built d.ts file paths * build(packages): prevent empty exports added to package.json during pack * docs(packages): update readme with custom conditions information --------- Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
149 lines
4.1 KiB
JavaScript
149 lines
4.1 KiB
JavaScript
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const path = require('path');
|
|
const webpack = require('webpack');
|
|
|
|
const CorsWorkerPlugin = require('./plugins/CorsWorkerPlugin');
|
|
|
|
module.exports = {
|
|
target: 'web',
|
|
entry: {
|
|
app: './public/app/index.ts',
|
|
swagger: './public/swagger/index.tsx',
|
|
},
|
|
experiments: {
|
|
// Required to load WASM modules.
|
|
asyncWebAssembly: true,
|
|
},
|
|
output: {
|
|
clean: true,
|
|
path: path.resolve(__dirname, '../../public/build'),
|
|
filename: '[name].[contenthash].js',
|
|
// Keep publicPath relative for host.com/grafana/ deployments
|
|
publicPath: 'public/build/',
|
|
},
|
|
resolve: {
|
|
conditionNames: ['@grafana-app/source', '...'],
|
|
extensions: ['.ts', '.tsx', '.es6', '.js', '.json', '.svg'],
|
|
alias: {
|
|
// some of data source plugins use global Prism object to add the language definition
|
|
// we want to have same Prism object in core and in grafana/ui
|
|
prismjs: require.resolve('prismjs'),
|
|
// due to our webpack configuration not understanding package.json `exports`
|
|
// correctly we must alias this package to the correct file
|
|
// the alternative to this alias is to copy-paste the file into our
|
|
// source code and miss out in updates
|
|
'@locker/near-membrane-dom/custom-devtools-formatter': require.resolve(
|
|
'@locker/near-membrane-dom/custom-devtools-formatter.js'
|
|
),
|
|
},
|
|
modules: [
|
|
// default value
|
|
'node_modules',
|
|
|
|
// required for grafana enterprise resolution
|
|
path.resolve('node_modules'),
|
|
|
|
// required to for 'bare' imports (like 'app/core/utils' etc)
|
|
path.resolve('public'),
|
|
],
|
|
fallback: {
|
|
buffer: false,
|
|
fs: false,
|
|
stream: false,
|
|
http: false,
|
|
https: false,
|
|
string_decoder: false,
|
|
},
|
|
},
|
|
ignoreWarnings: [
|
|
/export .* was not found in/,
|
|
{
|
|
module: /@kusto\/language-service\/bridge\.min\.js$/,
|
|
message: /^Critical dependency: the request of a dependency is an expression$/,
|
|
},
|
|
],
|
|
plugins: [
|
|
new webpack.NormalModuleReplacementPlugin(/^@grafana\/schema\/dist\/esm\/(.*)$/, (resource) => {
|
|
resource.request = resource.request.replace('@grafana/schema/dist/esm', '@grafana/schema/src');
|
|
}),
|
|
new CorsWorkerPlugin(),
|
|
new webpack.ProvidePlugin({
|
|
Buffer: ['buffer', 'Buffer'],
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{
|
|
from: 'public/img',
|
|
to: 'img',
|
|
},
|
|
{
|
|
from: 'public/maps',
|
|
to: 'maps',
|
|
},
|
|
{
|
|
from: 'public/gazetteer',
|
|
to: 'gazetteer',
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: require.resolve('jquery'),
|
|
loader: 'expose-loader',
|
|
options: {
|
|
exposes: ['$', 'jQuery'],
|
|
},
|
|
},
|
|
{
|
|
test: /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
|
|
type: 'asset/resource',
|
|
generator: { filename: 'static/img/[name].[hash:8][ext]' },
|
|
},
|
|
{
|
|
// Required for msagl library (used in Nodegraph panel) to work
|
|
test: /\.m?js$/,
|
|
resolve: {
|
|
fullySpecified: false,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
// https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-3
|
|
optimization: {
|
|
runtimeChunk: 'single',
|
|
splitChunks: {
|
|
chunks: 'all',
|
|
minChunks: 1,
|
|
cacheGroups: {
|
|
moment: {
|
|
test: /[\\/]node_modules[\\/]moment[\\/].*[jt]sx?$/,
|
|
chunks: 'initial',
|
|
priority: 20,
|
|
enforce: true,
|
|
},
|
|
angular: {
|
|
test: /[\\/]node_modules[\\/]angular[\\/].*[jt]sx?$/,
|
|
chunks: 'initial',
|
|
priority: 50,
|
|
enforce: true,
|
|
},
|
|
defaultVendors: {
|
|
test: /[\\/]node_modules[\\/].*[jt]sx?$/,
|
|
chunks: 'initial',
|
|
priority: -10,
|
|
reuseExistingChunk: true,
|
|
enforce: true,
|
|
},
|
|
default: {
|
|
priority: -20,
|
|
chunks: 'all',
|
|
test: /.*[jt]sx?$/,
|
|
reuseExistingChunk: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|