我想将nodejs代理列表模块导入angular2应用程序 . 我正在使用带有Angular2和Webpack配置的Electron .
- 这是我的app.component.ts
import { Component } from '@angular/core';
const ProxyLists = require('proxy-lists');
@Component({
selector: 'app',
templateUrl: './app/app.component.html',
})
export class AppComponent {
proxies: any[] = [];
constructor() {
}
getProxies() {
let options = {
countries: ['us', 'ca']
};
var gettingProxies = ProxyLists.getProxies(options);
gettingProxies.on('data', function (proxies) {
console.log(proxies);
})
}
test() {
console.log("work");
}
}
- 这是webpack.config.js
var path = require('path');
var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
module.exports = {
devtool: 'source-map',
entry: {
'angular2': [
'rxjs',
'reflect-metadata',
'zone.js',
'@angular/core',
'@angular/router',
'@angular/http'
],
'app': './src/main'
},
output: {
path: __dirname + '/build/',
publicPath: 'build/',
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js'
},
resolve: {
extensions: ['.ts','.js','.json', '.css', '.html'],
alias: {
materializecss: 'materialize-css/dist/css/materialize.css',
materialize: 'materialize-css/dist/js/materialize.js',
}
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: [ /node_modules/ ]
},
{
test: /^((?!materialize).)*\.css$/,
loader: 'raw-loader' },
{
test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
loader: 'url-loader?limit=100000'
},
]
},
plugins: [
new CommonsChunkPlugin({ name: 'angular2', filename: 'angular2.js', minChunks: Infinity }),
new CommonsChunkPlugin({ name: 'common', filename: 'common.js' }),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Hammer: "hammerjs/hammer"
})
],
target: 'electron-renderer'
};
</pre>
- 当我运行应用程序时,我收到此错误 . app.png
1 回答
我从未使用angularjs2,但你应该在nodejs服务器脚本上创建静态的那些模块 .