繁体   English   中英

将Angular 2 Webpack包含在第三方库中

[英]Include Angular 2 webpack with third party libraries

我已经使用一些第三方库(如Bootstrap,jQuery,ng2-oauth2,Wijmo等)创建了一个小项目。我决定使用webpack捆绑我的项目。 谁能帮助我将那些第三方库包含到我的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';`

这是正确的导入方式吗? 它显示此错误:

错误页面

我已经这样使用过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用于将页脚部分与动态脚本对齐。

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

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'
          })
        ]

对于引导程序和其他第三方库,您可以直接导入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';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM