Skip to content

Commit 5ee4b3e

Browse files
authored
build(webpack): Use fork-ts webpack plugin (#15587)
* run babel-loader + fork ts check when NOT in CI, otherwise use ts-loader for tsx files * change tsconfig option for JSX to "preserve" so that we can use babel (and specifically emotion babel preset css plugin)
1 parent b8981e9 commit 5ee4b3e

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"emotion-theming": "10.0.27",
7070
"file-loader": "^3.0.1",
7171
"focus-visible": "^5.0.2",
72+
"fork-ts-checker-webpack-plugin": "^1.5.1",
7273
"fuse.js": "^3.4.6",
7374
"gettext-parser": "1.3.1",
7475
"intersection-observer": "^0.7.0",

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"experimentalDecorators": true,
2727

2828
"esModuleInterop": true,
29-
"jsx": "react",
29+
"jsx": "preserve",
3030
"baseUrl": ".",
3131
"outDir": "src/sentry/static/sentry/dist",
3232
"paths": {

webpack.config.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const CompressionPlugin = require('compression-webpack-plugin');
1414
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
1515
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
1616
const CopyPlugin = require('copy-webpack-plugin');
17+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
1718

1819
const babelConfig = require('./babel.config');
1920

@@ -30,6 +31,7 @@ const SENTRY_WEBPACK_PROXY_PORT = env.SENTRY_WEBPACK_PROXY_PORT;
3031
const USE_HOT_MODULE_RELOAD =
3132
!IS_PRODUCTION && SENTRY_BACKEND_PORT && SENTRY_WEBPACK_PROXY_PORT;
3233
const NO_DEV_SERVER = env.NO_DEV_SERVER;
34+
const IS_CI = !!env.CI || !!env.TRAVIS;
3335

3436
// Deploy previews are built using netlify. We can check if we're in netlifys
3537
// build process by checking the existence of the PULL_REQUEST env var.
@@ -183,6 +185,14 @@ const cacheGroups = {
183185
};
184186

185187
const babelOptions = {...babelConfig, cacheDirectory: true};
188+
const babelLoaderConfig = {
189+
loader: 'babel-loader',
190+
options: babelOptions,
191+
};
192+
193+
const tsLoaderConfig = {
194+
loader: 'ts-loader',
195+
};
186196

187197
/**
188198
* Main Webpack config for Sentry React SPA.
@@ -214,27 +224,15 @@ let appConfig = {
214224
test: /\.jsx?$/,
215225
include: [staticPrefix],
216226
exclude: /(vendor|node_modules|dist)/,
217-
use: {
218-
loader: 'babel-loader',
219-
options: babelOptions,
220-
},
227+
use: babelLoaderConfig,
221228
},
222229
{
223230
test: /\.tsx?$/,
224231
include: [staticPrefix],
225232
exclude: /(vendor|node_modules|dist)/,
226-
use: [
227-
{
228-
loader: 'babel-loader',
229-
options: babelOptions,
230-
},
231-
{
232-
loader: 'ts-loader',
233-
options: {
234-
transpileOnly: false,
235-
},
236-
},
237-
],
233+
// Make sure we typecheck in CI, but not for local dev since that is run with
234+
// the fork-ts plugin
235+
use: !IS_CI ? babelLoaderConfig : [babelLoaderConfig, tsLoaderConfig],
238236
},
239237
{
240238
test: /\.po$/,
@@ -320,6 +318,14 @@ let appConfig = {
320318

321319
new SentryInstrumentation(),
322320

321+
...(!IS_CI
322+
? [
323+
new ForkTsCheckerWebpackPlugin({
324+
tsconfig: path.resolve(__dirname, './tsconfig.json'),
325+
}),
326+
]
327+
: []),
328+
323329
...localeRestrictionPlugins,
324330
],
325331
resolve: {

yarn.lock

+14
Original file line numberDiff line numberDiff line change
@@ -6749,6 +6749,20 @@ [email protected]:
67496749
tapable "^1.0.0"
67506750
worker-rpc "^0.1.0"
67516751

6752+
fork-ts-checker-webpack-plugin@^1.5.1:
6753+
version "1.6.0"
6754+
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-1.6.0.tgz#a81fd1c6bf5258fa5318cf3e9a7e9bac006f7917"
6755+
integrity sha512-vqOY5gakcoon2s12V7MMe01OPwfgqulUWFzm+geQaPPOBKjW1I7aqqoBVlU0ECn97liMB0ECs16pRdIGe9qdRw==
6756+
dependencies:
6757+
babel-code-frame "^6.22.0"
6758+
chalk "^2.4.1"
6759+
chokidar "^2.0.4"
6760+
micromatch "^3.1.10"
6761+
minimatch "^3.0.4"
6762+
semver "^5.6.0"
6763+
tapable "^1.0.0"
6764+
worker-rpc "^0.1.0"
6765+
67526766
form-data@~2.3.2:
67536767
version "2.3.3"
67546768
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"

0 commit comments

Comments
 (0)