简体   繁体   English

MVC6新的缩小版本和Bower / NPM捆绑在一起

[英]MVC6 new minification and bundling with Bower/NPM

I started getting up to date with the ASP.NET 5 and MVC 6, and I see a lot of internet posts about Bower VS NPM. 我开始了解ASP.NET 5和MVC 6的最新知识,并且看到很多有关Bower VS NPM的互联网帖子。

  • The default started MVC template however uses both , is this required for the taskrunner (gulp) to work or is there another reason? 默认启动的MVC模板同时使用两者 ,这是任务运行器(gulp)所需的功能,还是有其他原因?

  • Second question is about the resource path, in MVC < 6 you could declare a relative path to research the minified/bundled js/css. 第二个问题是关于资源路径的,在MVC <6中,您可以声明一个相对路径来研究缩小/捆绑的js / css。 This way each MVC View would have its own path to its own specific js/css. 这样,每个MVC视图将有其自己的通往其自己特定js / css的路径。 How can I do this with gulp? 我该怎么做?

  • In MVC < 6 the js/css would NOT minify when debug enabled (as default setting), so it remains readable. 在MVC <6中,启用调试(默认设置)时,js / css不会最小化,因此它保持可读性。 I see the option to use an if-like statement on the environment variable like 我看到在环境变量上使用类似if语句的选项

    environment names="Development">script path 环境名称=“开发”>脚本路径

and another one for production in the view. 另一个用于视图中的生产。 This seems very cumbersome, is there a simple solution for not minifying in debug instead of having to list all paths twice (one minified and one not)? 这似乎很麻烦,是否有一个简单的解决方案,可以在调试中不进行最小化,而不必两次列出所有路径(一条缩小而另一条没有列出)?

Have one version of watch minify your js files and one that doesn't. 有一种版本的watch可以缩小您的js文件,而另一种版本则可以。 Either way all of your project paths can just point to the built js file to prevent having to switch back and forth for dev or prod. 无论哪种方式,您所有的项目路径都可以指向内置的js文件,以防止为开发或生产而来回切换。 You would need to break the minify stuff out of the 'scripts' task below and create a task that just does that. 您需要将缩小的内容从下面的“脚本”任务中分解出来,并创建一个可以完成此任务的任务。

//Concatenate & Minify JS
gulp.task('minscripts', function () {
    return gulp.src(config.alljs, { base: 'public/' })
        .pipe($.concat('all.js'))
        .pipe(gulp.dest('_build'))
        .pipe($.rename('all.min.js'))
        .pipe($.uglify())
        .pipe(gulp.dest(config.build));
});

gulp.task('scripts', function () {
    return gulp.src(config.alljs, { base: 'public/' })
        .pipe($.concat('all.js'))
        .pipe(gulp.dest('_build'))
        .pipe($.rename('all.min.js'))
        .pipe(gulp.dest(config.build));
});

gulp.task('watchWith', function () {
    gulp.watch('public/app/views/*.js', ['lint', 'minscripts']); //<- runs 'scripts' here
    gulp.watch('public/css/*.less', ['less']);
});

gulp.task('watchWithout', function () {
    gulp.watch('public/app/views/*.js', ['lint', 'scripts']);
    gulp.watch('public/css/*.less', ['less']);
});

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

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