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