在角度2应用程序中导入节点js模块

时间:2017-03-09 06:30:12

标签: node.js angular webpack electron

我想将nodejs proxy-lists模块导入angular2应用程序。 我正在使用带有Angular2和Webpack配置的Electron。

  1. 这是我的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"); } }
  2. 这是webpack.config.js

    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>
    
  3. 运行应用程序时,出现此错误。 app.png

1 个答案:

答案 0 :(得分:-1)

我从未使用过angularjs2,但你应该在nodejs服务器脚本上创建静态的那些模块。

def names = ['Foo', 'Bar', 'Fooey']
def firstAlphabetVsNames = names.groupBy { it.charAt(0) } // [F:[Foo, Fooey], B:[Bar]]