Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

injecting node_modules files add index.js content as main index.html code again #233

Open
zymr-keshav opened this issue Dec 19, 2017 · 0 comments

Comments

@zymr-keshav
Copy link

zymr-keshav commented Dec 19, 2017

mac os 10.13.1
gulp-inject v 4.3.0

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var $ = require('gulp-load-plugins')();
var es = require('event-stream');

var mainNPMFiles = require('npmfiles');

// var wiredep = require('wiredep').stream;
// var _ = require('lodash');


gulp.task('inject-reload', ['inject'], function() {
  $.connect.reload();
});

gulp.task('inject', ['scripts', 'styles'], function() {
  var injectStyles = gulp.src([
    path.join(conf.paths.tmp, '/serve/app/**/*.css'),
    path.join('!' + conf.paths.tmp, '/serve/app/vendor.css')
  ]);

  var injectScripts = gulp.src([
      path.join(conf.paths.src, '/app/**/*.js'),
      path.join('!' + conf.paths.src, '/app/**/*.spec.js'),
      path.join('!' + conf.paths.src, '/app/**/*.mock.js')
    ])
    // support for es6
    .pipe($.babel({"presets": [ ["env", { modules: false}] ], compact: false}))
    .pipe($.angularFilesort()).on('error', conf.errorHandler('AngularFilesort'));

  // for 3rd party js files
  var injectOptions = {
    ignorePath: [conf.paths.src, path.join(conf.paths.tmp, '/serve')],
    addRootSlash: false
  };

  var injectVendor = gulp.src([path.join(conf.paths.src, '/libs/**/*.js')], {
    read: false
  });
  var vendorOptions = {
    starttag: '<!-- inject:vendor -->',
    ignorePath: [conf.paths.src, path.join(conf.paths.tmp, '/serve')],
    addRootSlash: false
  };

  var npmVendors = gulp.src(mainNPMFiles( {nodeModulesPath: '../node_modules/'} ));

  var npmOptions = {
    relative: true,
    starttag: '<!-- inject:npm -->',
    ignorePath: [conf.paths.src, path.join(conf.paths.tmp, '/serve')],
    addRootSlash: false
  };

  return gulp.src(path.join(conf.paths.src, '/*.html'))
    .pipe($.inject(injectStyles, injectOptions))
    .pipe($.inject(injectScripts, injectOptions))
    .pipe($.inject(injectVendor, vendorOptions))
    .pipe($.inject(npmVendors, npmOptions))
    .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve')));
});

###.tmp/index.html

<!doctype html>
<html ng-app="app">

<head>
    <meta charset="utf-8">
    <base href="/" />
    <title ng-bind="state.current.data.pageTitle"></title>
    <meta name="description" content="Zeus System">
    <meta name="viewport" content="width=device-width">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <!-- build:css({.tmp/serve,src}) styles/vendor.css -->
    <!-- bower:css -->
    <!-- run `gulp inject` to automatically populate bower styles dependencies -->
    <!-- endbower -->
    <!-- endbuild -->
    <!-- build:css({.tmp/serve,src}) styles/app.css -->
    <!-- inject:css -->
    <link rel="stylesheet" href="app/index.css">
    <!-- endinject -->
    <!-- endbuild -->
</head>

<body ng-controller="MainController as main">
    <div ng-include="'app/views/common/content.html'"></div>
    <!-- build:js(src) scripts/vendor.js -->
    <!-- inject:npm -->
    <script src="../node_modules/@uirouter/angularjs/release/ui-router-angularjs.js"></script>
    <script src="../node_modules/angular/index.js"></script>
    <script src="../node_modules/angular-animate/index.js"></script>
    <script src="../node_modules/angular-aria/index.js"></script>
    <script src="../node_modules/angular-chart.js/dist/angular-chart.js"></script>
    <script src="../node_modules/angular-messages/index.js"></script>
    <script src="../node_modules/angular-recaptcha/index.js"></script>
    <script src="../node_modules/angular-resource/index.js"></script>
    <script src="../node_modules/angular-sanitize/index.js"></script>
    <script src="../node_modules/angular-toastr/index.js"></script>
    <script src="../node_modules/angular-touch/index.js"></script>
    <script src="../node_modules/angular-ui-bootstrap/index.js"></script>
    <script src="../node_modules/angular-ui-sortable/src/sortable.js"></script>
    <script src="../node_modules/angular-ui-validate/index.js"></script>
    <script src="../node_modules/chart.js/dist/Chart.bundle.min.js"></script>
    <script src="../node_modules/jquery/dist/jquery.js"></script>
    <script src="../node_modules/moment/moment.js"></script>
    <script src="../node_modules/ng-stomp/dist/ng-stomp.min.js"></script>
    <script src="../node_modules/ng-table/dist/ng-table.js"></script>
    <script src="../node_modules/ngstorage/ngStorage.js"></script>
    <script src="../node_modules/pace/pace.js"></script>
    <!-- endinject -->
    <!-- inject:vendor -->
    <!-- files in the es5 vendor folder will be injected here -->
    <!-- endinject -->
    <!-- endbuild -->
    <!-- build:js({.tmp/serve,.tmp/partials,src}) scripts/app.js -->
    <!-- inject:js -->
    <script src="app/index.module.js"></script>
    ...
    <script src="app/app.constant.js"></script>
    <!-- endinject -->
    <!-- inject:partials -->
    <!-- angular templates will be automatically converted in js and inserted here -->
    <!-- endinject -->
    <!-- endbuild -->
</body>

</html>

 

all these node_modules/packages/index.js has the index.html code when checking in the console.

why so?

also tried without realtive options

see the screenshot
zymr screen shot 2017-12-19 at 10 59 29 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant