grunt cableep重复js文件注入

时间:2018-12-11 15:15:52

标签: angularjs dependency-injection gruntjs wiredep grunt-wiredep

我正在尝试从Bower和wiredep迁移旧的AngularJS项目。我使用bower-away来准备从bower.jsonpackage.json的依存关系。现在,我可以使用yarn构建所有依赖项。现在,先前的bower_components位于node-modules/@bower_components中。

我正在尝试使用wiredep-away或什至wiredep使其正常工作。使用wiredep-away,我可以使用以下代码注入依赖项。

grunt.registerTask('testing','',function(){
    require('wiredep-away')({
      src: './app/index.html',
      directory: './node_modules/@bower_components',
      bowerJson: require('./package.json'),
      dependencies: true,
      includeSelf: false,
      devDependencies: false,
      exclude: [],
      overrides: {
       },
      fileTypes: {
        html: {
          block: /(([ \t]*)<!--\s*bower_custom:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
        },
      }
    });
  });   

我的package.json看起来像这样

 {
  "name": "xyzApp",
  "version": "2.4.2",
  "dependencies": {
    "@bower_components/jquery": "jquery/jquery-dist#~3.1.1",
    "@bower_components/angular": "angular/bower-angular#~1.5.8",
    "@bower_components/angular-animate": "angular/bower-angular-animate#~1.5.8",
    "@bower_components/angular-aria": "angular/bower-angular-aria#^1.7.2",
    "@bower_components/angular-cookies": "angular/bower-angular-cookies#~1.5.8",
    "@bower_components/angular-elastic": "monospaced/angular-elastic#~2.5.1",
    "@bower_components/angular-material": "angular/bower-material#~1.1.1",
    "@bower_components/angular-messages": "angular/bower-angular-messages#^1.7.2",
    "@bower_components/angular-mocks": "angular/bower-angular-mocks#~1.5.8",
    "@bower_components/angular-resource": "angular/bower-angular-resource#~1.5.8",
    "@bower_components/angular-route": "angular/bower-angular-route#~1.5.8",
    "@bower_components/angular-sanitize": "angular/bower-angular-sanitize#~1.5.8",
    "@bower_components/angular-scenario": "angular/bower-angular-scenario#~1.5.8",
    "@bower_components/angular-ui-router": "angular-ui/angular-ui-router-bower#~0.3.1",
    "@bower_components/angular-uuid4": "monicao/angular-uuid4#~0.3.1",
    "@bower_components/bootstrap-sass-official": "twbs/bootstrap-sass#~3.3.7",
    "@bower_components/es5-shim": "es-shims/es5-shim#~4.5.9",
    "@bower_components/jplayer": "happyworm/jPlayer#2.9.2",
    "@bower_components/json3": "bestiejs/json3#~3.3.2",
    "@bower_components/ngInfiniteScroll": "ng-infinite-scroll/ng-infinite-scroll-bower#~1.3.0"
  },

文件注入时存在重复的问题

<!-- bower_custom:js -->
<script src="../node_modules/@bower_components/jquery/dist/jquery.js"></script>
<script src="../node_modules/@bower_components/angular/angular.js"></script>
<script src="../node_modules/@bower_components/angular/angular.js"></script>
<script src="../node_modules/@bower_components/angular-animate/angular-animate.js"></script>
<script src="../node_modules/@bower_components/angular-cookies/angular-cookies.js"></script>
<script src="../node_modules/@bower_components/angular-elastic/elastic.js"></script>
<script src="../node_modules/@bower_components/angular-animate/angular-animate.js"></script>
<script src="../node_modules/@bower_components/angular-aria/angular-aria.js"></script>
<script src="../node_modules/@bower_components/angular-messages/angular-messages.js"></script>
<script src="../node_modules/@bower_components/angular-material/angular-material.js"></script>
<script src="../node_modules/@bower_components/angular-resource/angular-resource.js"></script>
<script src="../node_modules/@bower_components/angular-route/angular-route.js"></script>
<script src="../node_modules/@bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="../node_modules/@bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="../node_modules/@bower_components/angular-uuid4/angular-uuid4.js"></script>
<script src="../node_modules/@bower_components/jquery/dist/jquery.js"></script>
<script src="../node_modules/@bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js"></script>
<script src="../node_modules/@bower_components/es5-shim/es5-shim.js"></script>
<script src="../node_modules/@bower_components/jplayer/dist/jplayer/jquery.jplayer.js"></script>
<script src="../node_modules/@bower_components/json3/lib/json3.js"></script>
<script src="../node_modules/@bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js"></script>
<!-- endbower -->

如何删除重复的注射?谢谢。

我很乐意听到其他可能在这里完成任务的艰巨任务。我没有使用webpack和browserify失败,如果不进行批量更改,我的项目将不兼容。我知道我已经接近解决方案了。

0 个答案:

没有答案