简体   繁体   English

从我的node_modules文件夹转换AngularJS的正确方法

[英]Correct way to transform AngularJS from my node_modules folder

I have chosen to use npm to include my UI dependencies like AngularJS. 我选择使用npm来包含UI依赖项,例如AngularJS。

After the installation the dependencies exist in the node_modules folder. 安装后,依赖项存在于node_modules文件夹中。

I can use AngularJS directly using <script src='/node_modules/angular/etc.'></script> 我可以直接使用<script src='/node_modules/angular/etc.'></script>

In reality, what I want to do is transform it as part of my gulp tasks, and move (minify/uglify if nescessary) to my assets folder. 实际上,我想做的是将其转换为我的任务任务的一部分,然后将其(如有必要,缩小/缩小)到我的资产文件夹中。

What is the correct way to do this? 正确的方法是什么? How do I find all the dependent libraries, is this a manual include or is there a better way? 我如何找到所有依赖库,这是手册包含的还是有更好的方法?

My gulp task looks like: 我的任务看起来像:

gulp.task("min:js", function () {
    gulp.src(["js/**/*.js", "!" + "js/**/*.min.js"], { base: "." })
        .pipe(concat("assets/js/site.min.js"))
        .pipe(uglify())
        .pipe(gulp.dest("."));
});

You seem to be on the right track with using Gulp, however, you'll soon realize that not using a bundler will be a bit more difficult that you want it to be if you are new to this approach. 您似乎在使用Gulp时走在正确的道路上,但是,您很快就会意识到,如果不熟悉捆绑方法,那么不使用捆绑器会更加困难。 I believe you will benefit from using a loader like Browserify or Webpack . 我相信您会从使用BrowserifyWebpack这样的加载程序中受益 Both of these will allow you to combine all of your client dependencies into bundles as you see fit. 这两种方法都可以让您根据需要将所有客户端依赖项组合到捆绑中。 These libraries will let you to use AMD and/or CommonJS to "require" your dependencies. 这些库使您可以使用AMD和/或CommonJS来“要求”您的依赖项。

You are clearly not using yeoman and bower, not that there's anything wrong in NOT using it. 您显然不是在使用yeoman和bower,也不是因为不使用它有什么问题。

https://github.com/yeoman/generator-angular https://github.com/yeoman/generator-angular

http://yeoman.io/codelab/ http://yeoman.io/codelab/

Have a look at Yeoman generators, in particular "generator-angular". 看一下Yeoman发电机,尤其是“ generator-angular”。 This will setup (scaffold) your angular project for you based on some (accepted) best practices. 这将根据一些(公认的)最佳实践为您设置(脚手架)您的角度项目。 And utilizes bower to manage your client side dependencies. 并利用Bower管理您的客户端依赖性。 Gulp is then (automatically configured) used to build/include/bundle the dependencies. 然后,使用Gulp(自动配置)来构建/包含/捆绑依赖项。

My suggestion is to install yeoman, and check the "generator-angular" generator, and then look at how gulp manages the building of the dependencies from the bower components. 我的建议是安装yeoman,并检查“ gener-angular”生成器,然后查看gulp如何管理Bower组件的依赖项构建。

Ie once you use something like a yeoman generator, most of the work is done for you, ie yeoman generator solves this particular problem of your with very little to no effort. 即,一旦您使用诸如yeoman生成器之类的东西,大部分工作就为您完成,即yeoman生成器只需很少甚至不费力就可以解决您的特定问题。

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

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