2017-10-01 13:02:25 -05:00
|
|
|
'use strict';
|
|
|
|
|
2023-01-23 05:15:05 -06:00
|
|
|
const browserslist = require('browserslist');
|
|
|
|
const { resolveToEsbuildTarget } = require('esbuild-plugin-browserslist');
|
2021-08-31 05:55:05 -05:00
|
|
|
const ESLintPlugin = require('eslint-webpack-plugin');
|
2019-08-30 07:02:31 -05:00
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2022-04-22 08:33:13 -05:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2019-08-30 07:02:31 -05:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2022-04-22 08:33:13 -05:00
|
|
|
const path = require('path');
|
|
|
|
const { DefinePlugin } = require('webpack');
|
|
|
|
const { merge } = require('webpack-merge');
|
|
|
|
|
2022-05-26 04:49:18 -05:00
|
|
|
const HTMLWebpackCSSChunks = require('./plugins/HTMLWebpackCSSChunks');
|
2022-04-22 08:33:13 -05:00
|
|
|
const common = require('./webpack.common.js');
|
2023-01-23 05:15:05 -06:00
|
|
|
const esbuildTargets = resolveToEsbuildTarget(browserslist(), { printUnknownTargets: false });
|
2023-06-01 03:23:09 -05:00
|
|
|
// esbuild-loader 3.0.0+ requires format to be set to prevent it
|
|
|
|
// from defaulting to 'iife' which breaks monaco/loader once minified.
|
|
|
|
const esbuildOptions = {
|
|
|
|
target: esbuildTargets,
|
|
|
|
format: undefined,
|
|
|
|
};
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2023-06-05 04:51:48 -05:00
|
|
|
module.exports = (env = {}) => {
|
|
|
|
return merge(common, {
|
2023-08-02 02:35:36 -05:00
|
|
|
devtool: 'source-map',
|
2019-08-30 07:02:31 -05:00
|
|
|
mode: 'development',
|
2018-05-28 06:49:15 -05:00
|
|
|
|
2019-08-30 07:02:31 -05:00
|
|
|
entry: {
|
|
|
|
app: './public/app/index.ts',
|
|
|
|
dark: './public/sass/grafana.dark.scss',
|
|
|
|
light: './public/sass/grafana.light.scss',
|
|
|
|
},
|
2018-04-18 08:01:36 -05:00
|
|
|
|
2019-08-30 07:02:31 -05:00
|
|
|
// If we enabled watch option via CLI
|
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/,
|
|
|
|
},
|
2019-07-19 23:46:41 -05:00
|
|
|
|
2019-08-30 07:02:31 -05:00
|
|
|
module: {
|
2020-01-30 03:54:11 -06:00
|
|
|
// Note: order is bottom-to-top and/or right-to-left
|
|
|
|
rules: [
|
2019-08-30 07:02:31 -05:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2023-06-01 03:23:09 -05:00
|
|
|
exclude: /node_modules/,
|
2021-08-31 05:55:05 -05:00
|
|
|
use: {
|
2023-01-23 05:15:05 -06:00
|
|
|
loader: 'esbuild-loader',
|
2023-06-01 03:23:09 -05:00
|
|
|
options: esbuildOptions,
|
2021-08-31 05:55:05 -05:00
|
|
|
},
|
2019-08-30 07:02:31 -05:00
|
|
|
},
|
2019-09-03 03:29:02 -05:00
|
|
|
require('./sass.rule.js')({
|
|
|
|
sourceMap: false,
|
2020-01-30 03:54:11 -06:00
|
|
|
preserveUrl: false,
|
2019-09-03 03:29:02 -05:00
|
|
|
}),
|
2020-01-30 03:54:11 -06:00
|
|
|
],
|
2019-08-30 07:02:31 -05:00
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2021-08-31 05:55:05 -05:00
|
|
|
// https://webpack.js.org/guides/build-performance/#output-without-path-info
|
|
|
|
output: {
|
|
|
|
pathinfo: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
// https://webpack.js.org/guides/build-performance/#avoid-extra-optimization-steps
|
|
|
|
optimization: {
|
2022-05-26 04:49:18 -05:00
|
|
|
moduleIds: 'named',
|
2021-08-31 05:55:05 -05:00
|
|
|
runtimeChunk: true,
|
|
|
|
removeAvailableModules: false,
|
|
|
|
removeEmptyChunks: false,
|
|
|
|
splitChunks: false,
|
|
|
|
},
|
|
|
|
|
2021-11-11 07:32:34 -06:00
|
|
|
// enable persistent cache for faster cold starts
|
|
|
|
cache: {
|
|
|
|
type: 'filesystem',
|
|
|
|
name: 'grafana-default-development',
|
|
|
|
buildDependencies: {
|
|
|
|
config: [__filename],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-08-30 07:02:31 -05:00
|
|
|
plugins: [
|
2021-08-31 05:55:05 -05:00
|
|
|
parseInt(env.noTsCheck, 10)
|
|
|
|
? new DefinePlugin({}) // bogus plugin to satisfy webpack API
|
2020-01-30 03:54:11 -06:00
|
|
|
: new ForkTsCheckerWebpackPlugin({
|
2021-08-31 05:55:05 -05:00
|
|
|
async: true, // don't block webpack emit
|
2020-10-01 03:50:56 -05:00
|
|
|
typescript: {
|
|
|
|
mode: 'write-references',
|
2021-04-06 07:51:35 -05:00
|
|
|
memoryLimit: 4096,
|
2020-10-01 03:50:56 -05:00
|
|
|
diagnosticOptions: {
|
|
|
|
semantic: true,
|
|
|
|
syntactic: true,
|
|
|
|
},
|
2020-06-22 09:15:29 -05:00
|
|
|
},
|
2020-10-01 03:50:56 -05:00
|
|
|
}),
|
2023-08-01 04:58:39 -05:00
|
|
|
parseInt(env.noLint, 10)
|
|
|
|
? new DefinePlugin({}) // bogus plugin to satisfy webpack API
|
|
|
|
: new ESLintPlugin({
|
|
|
|
cache: true,
|
|
|
|
lintDirtyModulesOnly: true, // don't lint on start, only lint changed files
|
|
|
|
extensions: ['.ts', '.tsx'],
|
|
|
|
}),
|
2019-08-30 07:02:31 -05:00
|
|
|
new MiniCssExtractPlugin({
|
2022-05-26 04:49:18 -05:00
|
|
|
filename: 'grafana.[name].[contenthash].css',
|
2019-08-30 07:02:31 -05:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: path.resolve(__dirname, '../../public/views/error.html'),
|
|
|
|
template: path.resolve(__dirname, '../../public/views/error-template.html'),
|
|
|
|
inject: false,
|
2019-09-03 03:29:02 -05:00
|
|
|
chunksSortMode: 'none',
|
2020-01-30 03:54:11 -06:00
|
|
|
excludeChunks: ['dark', 'light'],
|
2019-08-30 07:02:31 -05:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: path.resolve(__dirname, '../../public/views/index.html'),
|
|
|
|
template: path.resolve(__dirname, '../../public/views/index-template.html'),
|
2019-12-05 01:30:39 -06:00
|
|
|
inject: false,
|
2019-09-03 03:29:02 -05:00
|
|
|
chunksSortMode: 'none',
|
2020-01-30 03:54:11 -06:00
|
|
|
excludeChunks: ['dark', 'light'],
|
2019-08-30 07:02:31 -05:00
|
|
|
}),
|
2022-05-26 04:49:18 -05:00
|
|
|
new HTMLWebpackCSSChunks(),
|
2021-08-31 05:55:05 -05:00
|
|
|
new DefinePlugin({
|
2019-08-30 07:02:31 -05:00
|
|
|
'process.env': {
|
2020-01-30 03:54:11 -06:00
|
|
|
NODE_ENV: JSON.stringify('development'),
|
|
|
|
},
|
2019-08-30 07:02:31 -05:00
|
|
|
}),
|
2020-01-30 03:54:11 -06:00
|
|
|
],
|
2019-08-30 07:02:31 -05:00
|
|
|
});
|
2023-06-05 04:51:48 -05:00
|
|
|
};
|