2017-02-15 61 views
0

鑑於以下gulp任務。 我得到錯誤輸出在腳本中使用webpack 2.2.1在腳本中解析ts-loader

Module not found: Error: Can't resolve 'app.ts' in 'wwwroot/js/admin'

gulp.task("admin:js", function (done) { 
    module.exports = { 
     context: "wwwroot/js/admin", 
     entry: ["app.ts", "zippy.ts"], 
     output: { 
      filename: "admin.js" 
     }, 
     devtool: "source-map", 
     module: { 
      rules: [ 
       { test: /\.ts$/, use: 'ts-loader' } 
      ] 
     } 
    }; 
    webpack(module.exports).run(onBuild(done)); 
}); 

與目錄結構

wwwroot\js\admin\app.ts 
wwwroot\js\admin\zippy.ts 

我收到此錯誤:

Version: webpack 2.2.1 
Time: 31ms 
     Asset  Size Chunks    Chunk Names 
    admin.js 2.87 kB  0 [emitted] main 
admin.js.map 2.61 kB  0 [emitted] main 
chunk {0} admin.js, admin.js.map (main) 40 bytes [entry] [rendered] 
    [0] multi app.ts zippy.ts 40 bytes {0} [built] 

ERROR in multi app.ts zippy.ts 
Module not found: Error: Can't resolve 'app.ts' in 'wwwroot/js/admin' 
@ multi app.ts zippy.ts 

ERROR in multi app.ts zippy.ts 
Module not found: Error: Can't resolve 'zippy.ts' in 'wwwroot/js/admin' 
@ multi app.ts zippy.ts 

這是一個路徑問題,因爲如果我從執行webpack命令行,在wwwroot\js\admin目錄中,沒有上下文路徑,文件正確綁定,並且都可以工作。

當我使用API​​腳本,並從項目根目錄執行(相對於.\wwwroot\js\admin),我得到錯誤輸出。

+0

來吧 - 這個問題太愚蠢了,甚至在14小時後甚至沒有引發單個評論......我的措辭很糟糕......這些路徑令我非常沮喪。 – Jim

回答

0

的WebPack確實不支持context配置條目的使用相對路徑

context改變如下:

module.exports = { 
    context: __dirname + "/wwwroot/js/admin", 
    ... 

校正的輸出。

Version: webpack 2.2.1 
Time: 2337ms 
     Asset  Size Chunks     Chunk Names 
    admin.js 1.24 MB  0 [emitted] [big] main 
admin.js.map 1.48 MB  0 [emitted]   main 
chunk {0} admin.js, admin.js.map (main) 1.24 MB [entry] [rendered] 
    [0] ./~/angular/index.js 48 bytes {0} [built] 
    [1] ./wwwroot/js/admin/app.ts 408 bytes {0} [built] 
    [2] ./wwwroot/js/admin/zippy.ts 1.16 kB {0} [built] 
    [3] ./~/angular/angular.js 1.24 MB {0} [built] 
    [4] multi ./app.ts ./zippy.ts 40 bytes {0} [built] 
[10:30:37] Finished 'admin:js' after 2.43 s