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