2016-10-07 31 views
14

Mam projekt kątowy2, który kompresuję/kompiluję z pakietem sieci Web.tslint-loader z pakietem internetowym 2.1.0-beta.25

Używam programu ładującego tslink z pakietem sieci Web, więc mam konfigurację powiązaną z tslint w webpack.config.js.

module.exports = { 
... 
tslint: { 
    configuration: { 
     rules: { 
      quotemark: [true, "double"] 
     } 
    }, 

    // tslint errors are displayed by default as warnings 
    // set emitErrors to true to display them as errors 
    emitErrors: false, 

    // tslint does not interrupt the compilation by default 
    // if you want any file with tslint errors to fail 
    // set failOnHint to true 
    failOnHint: true, 

    // name of your formatter (optional) 
    formatter: "", 

    // path to directory containing formatter (optional) 
    formattersDirectory: "node_modules/tslint-loader/formatters/", 

    // These options are useful if you want to save output to files 
    // for your continuous integration server 
    fileOutput: { 
     // The directory where each file"s report is saved 
     dir: "./webpack-log/", 

     // The extension to use for each report"s filename. Defaults to "txt" 
     ext: "xml", 

     // If true, all files are removed from the report directory at the beginning of run 
     clean: true, 

     // A string to include at the top of every report file. 
     // Useful for some report formats. 
     header: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<checkstyle version=\"5.7\">", 

     // A string to include at the bottom of every report file. 
     // Useful for some report formats. 
     footer: "</checkstyle>" 
    } 
}, 
... 
preLoaders: [ 
     { 
      test: /\.ts$/, 
      loader: "tslint" 
     } 
    ], 
} 
} 

zaktualizowałem WebPack 1.13.1 do 2.1.0-beta.25 i konfiguracja tslint przerywa proces powikłań npm run build.

Zmieniłem dyrektywę preLoaders do loaders

module: { 
     .... 
     { 
      test: /\.ts$/, 
      loader: 'tslint', 
      exclude: /(node_modules)/, 
      enforce: 'pre' 
     }, 
    ], 
} 

to nie wystarczy bo ciągle pojawia się błąd

For loader options: webpack 2 no longer allows custom properties in configuration. 
Loaders should be updated to allow passing options via loader options in module.rules. 

więc należy przenieść konfigurację tslint i umieścić go gdzieś indziej. trochę tu zagubiony. więc wszelkie informacje dotyczące tego zagadnienia będą bardzo mile widziane.

dziękuję!

Odpowiedz

53

dla innych, którzy mają problemy z obciążenia wstępnego w WebPacka 2. W beta v2.1 -Beta.23 następuje przełamanie zmian za pomocą pre/postLoaders.

Najpierw należy zmienić nazwę sekcji "ładowniki" na "reguły". Również pre/postLoaders jest teraz zdefiniowany zgodnie z regułami.

W moim przypadku użyłem tslint jako preLoader. Aby dodać regułę pre/postLoader do reguł, dodaj właściwość enforce o wartości: pre lub post.

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

Więcej informacji w komunikacie na github: Webpack v2.1.0-beta.23

W informacji uwalnianiu jest również link do pull request który pokazuje potrzebnych zmian wykraczających od v2.1.0-beta.22 do v2.1.0-beta.23 w pliku konfiguracyjnym WebPack. Tam możesz zobaczyć, że potrzebujesz również LoaderOptionsPlugin.

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

Niesamowite answer.Can używam node_modules bez nawiasu? Dziękuję. – skiabox

2

ok .. więc po prostu potrzebne, aby przenieść definicję tslint under:

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

i ogłosił

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

Jeśli nie chcesz, aby dodać plugin, można zrobić coś takiego,

module: { 
    rules: [ 
    { 
     enforce: 'pre', 
     test: /\.ts$/, 
     loader: 'tslint-loader?' + JSON.stringify({ 
     emitErrors: true, 
     failOnHint: true 
     }) 
    } 
    ] 
}