Skip to content

Commit

Permalink
Chore: Move babel config to a root babel.config.json (grafana#41615)
Browse files Browse the repository at this point in the history
* Chore: Move babel config to a root babel.config.json

* Re-add babel cache settings to webpack

* Re-add production browserlist in babel config

* re-add babel hot refresh config

* fix storybook
  • Loading branch information
joshhunt authored Nov 18, 2021
1 parent 7dcc5ca commit 3b497f3
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 63 deletions.
58 changes: 58 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"babelrc": false,
// Note: order is bottom-to-top and/or right-to-left
"presets": [
[
"@babel/preset-env",
{
"bugfixes": true,
"browserslistEnv": "dev",
"useBuiltIns": "entry",
"corejs": "3.10"
}
],
[
"@babel/preset-typescript",
{
"allowNamespaces": true,
"allowDeclareFields": true
}
],
[
"@babel/preset-react",
{
"runtime": "automatic"
}
]
],
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"allowNamespaces": true,
"allowDeclareFields": true
}
],
["@babel/plugin-proposal-object-rest-spread", { "loose": true }],
"@babel/plugin-transform-react-constant-elements",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-syntax-dynamic-import", // needed for `() => import()` in routes.ts
"angularjs-annotate"
],
"env": {
"production": {
"presets": [
[
"@babel/preset-env",
{
"browserslistEnv": "production"
}
]
]
},
"hot": {
"plugins": ["react-refresh/babel"]
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"repository": "github:grafana/grafana",
"scripts": {
"api-tests": "jest --notify --watch --config=devenv/e2e-api-tests/jest.js",
"build": "webpack --config scripts/webpack/webpack.prod.js",
"build:nominify": "webpack --config scripts/webpack/webpack.prod.js --env noMinify=1",
"build": "NODE_ENV=production webpack --config scripts/webpack/webpack.prod.js",
"build:nominify": "yarn run build --env noMinify=1",
"dev": "webpack --progress --color --config scripts/webpack/webpack.dev.js",
"e2e": "./e2e/start-and-run-suite",
"e2e:debug": "./e2e/start-and-run-suite debug",
Expand All @@ -35,7 +35,7 @@
"prettier:check": "prettier --list-different \"**/*.{scss,md,mdx}\"",
"prettier:write": "prettier --list-different \"**/*.{scss,md,mdx}\" --write",
"start": "yarn themes:generate && webpack --progress --color --watch --env noTsCheck=0 --config scripts/webpack/webpack.dev.js",
"start:hot": "yarn themes:generate && webpack serve --progress --color --config scripts/webpack/webpack.hot.js",
"start:hot": "yarn themes:generate && NODE_ENV=hot webpack serve --progress --color --config scripts/webpack/webpack.hot.js",
"start:noTsCheck": "yarn themes:generate && webpack --progress --color --watch --env noTsCheck=1 --config scripts/webpack/webpack.dev.js",
"stats": "webpack --mode production --config scripts/webpack/webpack.prod.js --profile --json > compilation-stats.json",
"storybook": "yarn workspace @grafana/ui storybook --ci",
Expand Down
1 change: 0 additions & 1 deletion packages/grafana-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const getBabelConfig = require('../../../scripts/webpack/babel.config');

const stories = ['../src/**/*.story.{js,jsx,ts,tsx,mdx}'];

Expand Down
53 changes: 0 additions & 53 deletions scripts/webpack/babel.config.js

This file was deleted.

6 changes: 4 additions & 2 deletions scripts/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const getBabelConfig = require('./babel.config');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = (env = {}) =>
Expand All @@ -34,7 +33,10 @@ module.exports = (env = {}) =>
test: /\.tsx?$/,
use: {
loader: 'babel-loader',
options: getBabelConfig({ BABEL_ENV: 'dev' }),
options: {
cacheDirectory: true,
cacheCompression: false,
},
},
exclude: /node_modules/,
},
Expand Down
6 changes: 4 additions & 2 deletions scripts/webpack/webpack.hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { DefinePlugin } = require('webpack');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const getBabelConfig = require('./babel.config');

module.exports = merge(common, {
devtool: 'inline-source-map',
Expand Down Expand Up @@ -46,7 +45,10 @@ module.exports = merge(common, {
test: /\.tsx?$/,
use: {
loader: 'babel-loader',
options: getBabelConfig({ BABEL_ENV: 'dev', REACT_REFRESH: true }),
options: {
cacheDirectory: true,
cacheCompression: false,
},
},
exclude: /node_modules/,
include: [path.resolve(__dirname, '../../public/'), path.resolve(__dirname, '../../packages/')],
Expand Down
6 changes: 4 additions & 2 deletions scripts/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const getBabelConfig = require('./babel.config');

module.exports = (env = {}) =>
merge(common, {
Expand All @@ -28,7 +27,10 @@ module.exports = (env = {}) =>
use: [
{
loader: 'babel-loader',
options: getBabelConfig(),
options: {
cacheDirectory: true,
cacheCompression: false,
},
},
],
},
Expand Down

0 comments on commit 3b497f3

Please sign in to comment.