webpack-encore icon indicating copy to clipboard operation
webpack-encore copied to clipboard

enableForkedTypeScriptTypesChecking stops validating the .ts file types

Open erikas-tranauskas opened this issue 1 year ago • 3 comments

I have a long running build times and I am trying to find a way to fix it. One of the solutions could be enabling the enableForkedTypeScriptTypesChecking. After enabling this setting it requires to install the fork-ts-checker-webpack-plugin@^6.0.0 and it cuts the build time almost in half, but the problem is that with this option enabled, the build doesn't validate the .ts files at all. I can remove all the types from the variables in .ts files and it still compiles successfully.

Any way to configure this to run smoothly?

My webpack.config.js:

const Encore = require('@symfony/webpack-encore');
const dotenvFlow = require('dotenv-flow');

if (!Encore.isRuntimeEnvironmentConfigured()) {
  Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'local');
}

Encore.setOutputPath('public/build/')
  .setPublicPath('/build')
  .addEntry('main', './assets/js/main.ts')
  .copyFiles({
    from: './assets/img',
    to: 'images/[path][name].[hash:8].[ext]',
  })
  .splitEntryChunks()
  .enableSingleRuntimeChunk()
  .cleanupOutputBeforeBuild()
  .enableBuildNotifications()
  .enableSourceMaps(!Encore.isProduction())
  .enableForkedTypeScriptTypesChecking()
  .enableVersioning(Encore.isProduction())
  .configureBabelPresetEnv((config) => {
    config.useBuiltIns = 'usage';
    config.corejs = 3;
  })
  .enableSassLoader()
  .enableTypeScriptLoader()
  .enableVueLoader()
  .configureDefinePlugin((options) => {
    const env = dotenvFlow.config({ silent: true });

    if (env.error) {
      throw env.error;
    }

    options['process.env'].PMP_API_BASE_URI = JSON.stringify(env.parsed.PMP_API_BASE_URI);
  });

Encore.addLoader({
  test: /\.ya?ml$/,
  loader: 'yaml-loader',
  type: 'json',
  options: { asJSON: true },
});

module.exports = Encore.getWebpackConfig();

erikas-tranauskas avatar May 12 '23 10:05 erikas-tranauskas

If you read the documentation of fork-ts-checker-webpack-plugin, it explicitly say that you will need to run type checking separately from your webpack build when using this plugin (disabling type checking is a big part of what makes it faster)

stof avatar May 12 '23 11:05 stof

I believe it should start this separate process by adding a plugin to webpack config.

.addPlugin(new ForkTsCheckerWebpackPlugin({ async: true })) doesn't do much. Any idea how to start it?

erikas-tranauskas avatar May 12 '23 13:05 erikas-tranauskas