Bower replacement in Visual Studio 2017 ASP.NET MVC Core Template

前端 未结 6 2328
情深已故
情深已故 2021-02-12 10:59

Lately I created a ASP.NET MVC Core project from scratch using Visual Studio 2017 (15.6.3). I discovered the usual JavaScript frameworks:

  • bootstrap
  • jquery
6条回答
  •  旧时难觅i
    2021-02-12 11:34

    Bower is dead. The team of bower is refering to Yarn (an addition on NPM).

    Since Visual Studio has some NPM support, I would go for it.

    Create in the root of your project a package.json (Todo so, right click your project, add item and search for NPM. You will find a npm Configuration File):

    {
      "name": "SomeName",
      "version": "1.0.0",
      "private": true,
      "dependencies": {
        "bootstrap": "3.3.7",
        "jquery": "3.3.1",
        "jquery-validation": "1.17.0",
        "jquery-validation-unobtrusive": "3.2.10",
        "jquery-ajax-unobtrusive": "3.2.4",
      }
    }
    

    Everytime you make changes to the json file, simple press CTRL + S. Visual Studio automaticly calls NPM and restores the packages. Also note, you have intellisence for the package names and version numbers.

    After migrating myself, I can not remember to not find a package on npm. But if it's the case for you, note you can reference a github repository directly.

    The depenencies are saved to node_modules folder. That's for the new package manager.

    Now you have the problem you need to bundle it for release (which you should have done with bower too). Bundeling is the process of combining your Javascript/CSS/Image assets to a single bundle.js, bundle.css, sprite.svg. These should be copied to the wwwroot folder.

    For doing so, we have a few options (I will only link to a few, since this would explode the scope of the question):

    • Webpack
    • Gulp
    • Grunt

提交回复
热议问题