gulp为JSP

时间:2017-06-27 02:54:50

标签: gulp

我有以下jsp文件,其中有css和jss的引用,现在我想使用gulp-inject,以便可以注入动态css和js

我将css文件保存在名为css C:\Softwares\Spring4MVCAngularJSExample\src\main\webapp\static\css)的文件夹中,我的javascript文件位于名为js (C:\Softwares\Spring4MVCAngularJSExample\src\main\webapp\static\js)的文件夹中

现在下面是我的jsp文件,其中我想要gulp注入发生请告诉我如何编写gulp注入任务,将动态注入.js和.css注入

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>  
    <title>AngularJS $http Example</title>  
    <style>
   </style>

     <link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
  </head>
  <body ng-app="myApp" class="ng-cloak">
      <div class="generic-container" ng-controller="UserController as ctrl">

                      </div>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
      <script src="<c:url value='/static/js/app.js' />"></script>
      <script src="<c:url value='/static/js/service/user_service.js' />"></script>
      <script src="<c:url value='/static/js/controller/user_controller.js' />"></script>
  </body>
</html>

我所尝试的是以下任务

gulp.task('inject', function(){

var resourcesToInject =  gulp.src(
    [sourcePaths.build + 'C:\\Softwares\\Spring4MVCAngularJSExample\\src\\main\\webapp\\static\\*.js'],
    {read: false});

return gulp
    .src('C:\\Softwares\\Spring4MVCAngularJSExample\\src\\main\\webapp\\WEB-INF\\views\\UserManagement2.jsp')
    .pipe($.inject(
      resourcesToInject,{
            transform: transoformResourceInclude
        }
      )
    )
    .pipe(gulp.dest('C:\\Softwares\\Spring4MVCAngularJSExample\\src\main\\webapp\\WEB-INF\\views\\'));
});

但它不起作用请告知它

1 个答案:

答案 0 :(得分:0)

尝试以下任务,它会从 app / client / public / js / / *和** app / client / public / app.js 中注入js依赖项index.html并将index.html写入构建目录

var inject = require('gulp-inject');
    gulp.task('inject-own', function() {
        gulp.src(['app/client/public/index.html'])
            .pipe(inject(gulp.src(['app/client/public/js/**/*','app/client/public/app.js'], {read: false})))            
            .pipe(gulp.dest('build'));
    });