我剛剛更新了我的Angular 2項目以使用Webpack 2,它工作得很好。但是,使用resolve: { alias: {...} }
密鑰時,我正面臨一個新問題。使用URL時未找到Webpack 2模塊
當我用的WebPack 1,此代碼只是工作得很好:使用時
ngOnInit() {
Promise.all([
require('http://www.eclipse.org/orion/editor/releases/current/built-editor.min.js'),
require('http://eclipse.org/orion/editor/releases/current/built-editor.css')
]).then(function() {
requirejs(['orion/editor/edit'], function (edit: any) {
this.orionEditor = edit({className: 'editor', parent: 'xml'})[0];
this.receiveXmlData();
}.bind(this));
}.bind(this));
}
現在的WebPack:
webpack.config.js
resolve: {
// http://webpack.github.io/docs/configuration.html#resolve-extensions
extensions: ['.ts', '.js', '.json', '.css', '.html'],
alias: {
"orion/editor/edit": "http://www.eclipse.org/orion/editor/releases/current/built-editor.min.js"
}
},
角度成分2,我總是得到一個錯誤,兩個文件無法解析。有人有想法嗎?
Module not found: Error: Can't resolve ' http://eclipse.org/orion/editor/releases/current/built-editor.css ' in [Angular-component file]
Module not found: Error: Can't resolve ' http://www.eclipse.org/orion/editor/releases/current/built-editor.min.js ' in 'C:\Applications\winery\enpro-winery\org.eclipse.winery.ui\src\app\instance\editXML'
我嘗試到現在:
const path = require('path');
resolve: {
extensions: ['.ts', '.js', '.json', '.css', '.html'],
alias: {
"orion/editor/edit": path.resolve("http://www.eclipse.org/orion/editor/releases/current/built-editor.min.js")
}
和
resolve: {
extensions: ['.ts', '.js', '.json', '.css', '.html'],
modules: [
path.join(__dirname, "src"),
"node_modules",
path.resolve("http://www.eclipse.org/orion/editor/releases/current/built-editor.min.js"),
path.resolve("http://eclipse.org/orion/editor/releases/current/built-editor.css")
]
},
謝謝,但我已經在我的webpack.common.js(它已經是必需的webpack 1) – lukas
您需要爲特定的擴展添加加載器並更改webpack.common.js中的以下配置例如上面的代碼 –
我已經在我的配置中具有所有這些加載器。正如我上面所說,它與webpack 1一起工作 – lukas