简体   繁体   English

如何在基于 angular-fullstack 的应用程序中包含库文件 (css/js)

[英]How to include library files (css/js) in angular-fullstack based app

I used a Yo Angular-Fullstack generator ( https://github.com/DaftMonk/generator-angular-fullstack ) and started an app and then tried installing Toastr from bower by doing -我使用了 Yo Angular-Fullstack 生成器( https://github.com/DaftMonk/generator-angular-fullstack )并启动了一个应用程序,然后尝试通过执行以下操作从凉亭安装 Toastr -

bower install angular-toastr

and now I want to add the toastr css and js files.现在我想添加 toastr css 和 js 文件。 They are located in the他们位于

bower_components/angular-toastr/dist

now how do i include them in my current project, so that they are included in the dist folder when i build the application using grunt.现在我如何将它们包含在我当前的项目中,以便在我使用 grunt 构建应用程序时将它们包含在 dist 文件夹中。

The folder structure is as follows -文件夹结构如下——

├── client
│   ├── app                 - All of our app specific components go in here
│   ├── assets              - Custom assets: fonts, images, etc…
│   ├── components          - Our reusable components, non-specific to to our app
│
├── e2e                     - Our protractor end to end tests
│
└── server
    ├── api                 - Our apps server api
    ├── auth                - For handling authentication with different auth strategies
    ├── components          - Our reusable or app-wide components
    ├── config              - Where we do the bulk of our apps configuration
    │   └── local.env.js    - Keep our environment variables out of source control
    │   └── environment     - Configuration specific to the node environment
    └── views               - Server rendered views

I use a grunt task called wiredep .我使用了一个名为wiredep的繁重任务。 It looks for the bower components that my app uses and add a reference to the css/js files to the file I specify.它查找我的应用程序使用的凉亭组件,并将对 css/js 文件的引用添加到我指定的文件中。

I'm using .NET BundleConfig for minification so my task setup looks like this:我使用 .NET BundleConfig 进行缩小,因此我的任务设置如下所示:

wiredep: {
        task: {
            src: [
            'App_Start/BundleConfig.cs'
            ],
            ignorePath: '..',
            fileTypes: {
                cs: {
                    block: /(([ \t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
                    detect: {
                        js: /<script.*src=['"](.+)['"]>/gi,
                        css: /<link.*href=['"](.+)['"]/gi
                    },
                    replace: {
                        js: '.Include("~{{filePath}}")',
                        css: '.Include("~{{filePath}}")'
                    }
                }
            },
            dependencies: true,
            devDependencies: false
        }
    },

The end result is something like this:最终结果是这样的:

bundles.Add(new ScriptBundle("~/bundles/thirdparty")
            //NOTE: auto-generated by a grunt task
            //anything between 'bower:js' and 'endbower' WILL BE LOST!
            //bower:js
            .Include("~/assets/angular/angular.js")
            .Include("~/assets/moment/moment.js")
            //endbower
            );

bundles.Add(new StyleBundle("~/bundles/css")
            //NOTE: auto-generated by a grunt task
            //anything between 'bower:css' and 'endbower' WILL BE LOST!
            //bower:css
            .Include("~/assets/nouislider/distribute/nouislider.min.css")
            //endbower
            .Include("~/Content/css/app.css")
            );

As I said, I'm using .NET BundleConfing, However, you can use and tags.正如我所说,我使用的是 .NET BundleConfing,但是,您可以使用和标记。 I think you just need to remove the option replace from the grunt task configuration.我认为您只需要从 grunt 任务配置中删除选项replace

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

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