tslint-loader with webpack 2.1.0-beta.25

旧街凉风 提交于 2019-12-03 11:14:45

For others who have problems with preloaders in webpack 2. In beta v2.1-beta.23 there are breaking changes with pre/postLoaders.

First the "loaders" section should be renamed to "rules". Also pre/postLoaders is now defined under rules.

In my case i was using tslint as a preLoader. To add a pre/postLoader to rules add the enforce property with value either pre or post.

module: {
    rules: [
        {
            enforce: 'pre',
            test: /\.tsx?$/,
            loader: 'tslint',
            exclude: /(node_modules)/,
        },
        {
            test: /\.tsx?$/,
            loaders: ['awesome-typescript-loader'],
            exclude: /(node_modules)/
        }
    ]
}

More info in the release on github: Webpack v2.1.0-beta.23

In the release info there is also a link to a pull request that shows the needed changes going from v2.1.0-beta.22 to v2.1.0-beta.23 in webpack config file. There you can see that you also need the LoaderOptionsPlugin.

plugins: [
    new webpack.LoaderOptionsPlugin({
        options: {
            tslint: {
                emitErrors: true,
                failOnHint: true
            }
        }
    })
]

ok.. so I just needed to move the tslint definition under:

plugins: [
    new LoaderOptionsPlugin({
        options: {
           tslint: {
             ...

and declared

const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin");

If you don't want to add a plugin, you can do something like this,

module: {
  rules: [
    {
      enforce: 'pre',
      test: /\.ts$/,
      loader: 'tslint-loader?' + JSON.stringify({
        emitErrors: true,
        failOnHint: true
      })
    }
  ]
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!