Is there an injector like grunt-wiredep that works for NPM dependencies?

前端 未结 1 2018
自闭症患者
自闭症患者 2021-02-05 04:46

Most packages nowadays are available in both NPM and Bower. I have to have NPM around, but I\'d like cut Bower out of the loop on my project.

I\'m currently relying on

1条回答
  •  死守一世寂寞
    2021-02-05 05:23

    You would be able to do that using a module bundler like Browserify or Webpack.

    For getting started with Browserify , you will need to first install it via NPM globally

    npm install -g browserify
    

    Then in your project , get the frontend library you want to include , like for example the angular library

    npm install --save angular
    

    Now you will need to use require() to make Browserify aware of the dependencies that it needs to fetch for the project to work (In case of Angular app, where you define the main module , add this first line)

    var angular = require('angular');
    
    angular
      .module('autocompleteDemo', [])
      .controller('DemoCtrl', DemoCtrl);
    

    For setting up the grunt-browserify task , first install it in the project

    npm install grunt-browserify --save-dev
    

    and configure the task as follows

    browserify: {
        main: {
            src: 'entry.js',
            dest: 'bundle.js'
        }
     }
    

    Lastly in your index.html , you will need to add markup for the bundle.js script

    
    

    Example code can be found at https://github.com/pra85/grunt-browserify-example

    0 讨论(0)
提交回复
热议问题