2017-04-06 70 views
0

我创建了一个小项目,使用Bootstrap,jQuery,ng2-oauth2,Wijmo等一些第三方库。我决定使用webpack捆绑我的项目。任何人都可以帮助我如何将这些第三方库纳入我的webpack实施?包含Angular 2与第三方库的webpack

我已导入像这样vendor.ts

// Angular 

import '@angular/platform-browser'; 
import '@angular/platform-browser-dynamic'; 
import '@angular/core'; 
import '@angular/common'; 
import '@angular/http'; 
import '@angular/router'; 
// RxJS 
import 'rxjs'; 
// Other vendors for example jQuery, Lodash or Bootstrap 
// You can import js, ts, css, sass, ... 
import 'bootstrap/dist/css/bootstrap.min.css'; 
import 'bootstrap-social/bootstrap-social.css'; 
import 'font-awesome/css/font-awesome.min.css'; 
import 'angular2-toaster/toaster.css'; 


import 'jquery/dist/jquery.min.js'; 
import 'bootstrap/dist/js/bootstrap.min.js';` 

这是导入正确的方法是什么?它显示了这个错误:

error page

我已经使用jQuery的是这样的:

import { Injectable } from '@angular/core'; 
declare var jQuery: any; 

@Injectable() 
export class FooterService { 

    //Get getFooterAlign Service 
    getFooterAlign(): any { 
     var getHeight = jQuery(window).height() - 225; 
     if (jQuery(".body-container").height() < getHeight) { 
      jQuery(".logInWrapper, .contentWrapper, .signupWrapper").css("height", jQuery(window).height() - 232); 
      jQuery(window).resize(function() { 
       jQuery(".logInWrapper, .contentWrapper").css("height", jQuery(window).height() - 225); 
      }); 
     } 
     else { 
      jQuery(".logInWrapper, .contentWrapper, .signupWrapper").css("height", jQuery(".body-container").height()); 
      jQuery(window).resize(function() { 
       jQuery(".logInWrapper, .contentWrapper").css("height", jQuery(".body-container").height()); 
      }); 
     } 
    } 

} 

jQuery是用来对准我的页脚节动态脚本。

我在代码中犯了什么错误?

+0

为什么不尝试的http://本地主机:9090 /#/工具入门为你Bootstrap需求? –

回答

0
after researching i found some solution for Jquery include below code in webpack.config.js file is working fine for me: 

    module.exports = { 
     resolve: { 
      extensions: ['.ts', '.js'], 
      alias: { 
       jquery: "jquery/src/jquery" 
      } 
     } 

---------- 

    plugins: [ 
      new webpack.ProvidePlugin({ 
       jQuery: 'jquery', 
       $: 'jquery', 
       jquery: 'jquery' 
      }) 
     ] 

的引导和其他第三方库u能在vendor.ts文件直接导入:

import 'bootstrap/dist/css/bootstrap.min.css'; 
import 'bootstrap-social/bootstrap-social.css'; 
import 'font-awesome/css/font-awesome.min.css'; 
import 'angular2-toaster/toaster.css'; 

import 'bootstrap/dist/js/bootstrap.min.js'; 
import 'angular2-jwt/angular2-jwt.js'; 
import '@ng-idle/core/bundles/core.umd.js'; 
import 'ng2-recaptcha'; 
import 'ng2-ckeditor'; 
import 'angular2-toaster/bundles/angular2-toaster.umd.js'; 
import 'ng2-bootstrap'; 
import 'crypto-js/crypto-js.js';