2017-04-06 73 views
1

我已經開始使用Angular 2項目的.Net Core。 Webpack和所有對我來說都很新,但我開始瞭解它們。如何指定特定的css/js包含在Webpack中?

我已經創建了一個項目dotnet new angular,我已經瞭解如何填充webpack.config.vendor.js來引用我的nugets包。

我現在有些CSS/JS,我想直接包括(沒有的NuGet包與他們)(不知道往哪裏放下襬,目前他們在/libs/somefolder/something.js/.css

於是,我就放在entry: {vendor:[]}陣列(webpack.config.vendor.js)兩個新的條目:

entry: { 
    vendor: [ 
     //Previous entries 
     '/libs/somefolder/something.js', 
     '/libs/somefolder/something.css', 
    ] 
}, 

但是當我運行webpack --config webpack.config.vendor.js,我得到錯誤:

ERROR in dll vendor Module not found: Error: Can't resolve '/libs/somefolder/something.js' in 'E:\My\Project.Web' @ dll vendor

ERROR in dll vendor Module not found: Error: Can't resolve '/libs/somefolder/something.css' in 'E:\My\Project.Web' @ dll vendor

那麼,我應該如何引用這些?

+0

你有沒有嘗試添加'模塊:[path.resolve(__目錄名稱, 「庫」), 「node_modules」]''在裏面的決心:{} 'config,然後將這些額外的庫指定爲'somefolder/something.js'?請參閱[resolve.modules](https://webpack.js.org/configuration/resolve/#resolve-modules) –

+0

@ DanielJ.G。這是解決方案。你能將你的評論轉換成答案嗎? – J4N

+0

今後請避免使用「標籤:標題」格式,要麼完全刪除標籤,要麼以更有機/自然的方式將標籤放入標題本身。閱讀這篇關於如何正確使用標籤的幫助中心文章http://stackoverflow.com/help/tagging – Tseng

回答

0

告訴webpack如何使用其resolve.modules配置屬性找到您的額外庫。通過這種方式,它將能夠找到放置在libs內的自定義庫,而不僅僅是node_modules中的那些庫。

webpack.config.vendor.js配置可能與此類似:

... 
resolve: { 
    extensions: [ '.js' ], 
    modules: [path.resolve(__dirname, "libs"), "node_modules"] 
} 
entry: { 
    vendor: [ 
     //Previous entries 
     '/libs/somefolder/something.js', 
     '/libs/somefolder/something.css', 
    ] 
}, 
... 
相關問題