symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

enableForkedTypeScriptTypesChecking stops validating the .ts file types #1207

Open erikas-tranauskas opened 1 year ago

erikas-tranauskas commented 1 year ago

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();
stof commented 1 year ago

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)

erikas-tranauskas commented 1 year ago

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?

carsonbot commented 1 month ago

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?