1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Why deploying app to a sub-directory it is looking at the root directory for node_modules?

Discussão em 'Angular' iniciado por sprocketholer, Novembro 5, 2024 às 15:43.

  1. I have a small Angular 2.0 app. It runs fine on my machines. It uses SystemJS and I have a gulp build tool for it. The problem is when I deploy it to a sub-directory it is look at the root directory for node_modules. It should be looking at:

    example.com/myapp/node_modules


    but it is looking at

    example.com/node_modules


    instead.

    tsconfig.json:

    {
    "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",?
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
    }
    }


    systemjs.config.js:

    (function (global) {
    System.config({
    paths: {
    // paths serve as alias
    'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
    // our app is within the app folder
    app: 'app',

    // angular bundles
    '@angular/core': 'npm:mad:angular/core/bundles/core.umd.js',
    '@angular/common': 'npm:mad:angular/common/bundles/common.umd.js',
    '@angular/compiler': 'npm:mad:angular/compiler/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:mad:angular/platform-browser/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:mad:angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:mad:angular/http/bundles/http.umd.js',
    '@angular/router': 'npm:mad:angular/router/bundles/router.umd.js',
    '@angular/forms': 'npm:mad:angular/forms/bundles/forms.umd.js',

    // other libraries
    'rxjs': 'npm:rxjs'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
    app: {
    main: './main.js',
    defaultExtension: 'js'
    },
    rxjs: {
    defaultExtension: 'js'
    }
    }
    });
    })(this);


    gulpfile.js:

    const gulp = require('gulp');
    const del = require('del');
    const typescript = require('gulp-typescript');
    const tscConfig = require('./tsconfig.json');
    const sourcemaps = require('gulp-sourcemaps');

    // clean the contents of the distribution directory
    gulp.task('clean', function () {
    return del('dist/**/*');
    });

    // TypeScript compile
    gulp.task('compile', ['clean', 'copy:libs', 'copy:assets'], function () {
    return gulp
    .src('app/**/*.ts')
    .pipe(sourcemaps.init())
    .pipe(typescript(tscConfig.compilerOptions))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist/app'));
    });

    // copy dependencies
    gulp.task('copy:libs', ['clean'], function() {
    return gulp.src([
    'node_modules/angular2/bundles/angular2-polyfills.js',
    'node_modules/systemjs/dist/system.src.js',
    'node_modules/rxjs/bundles/Rx.js',
    'node_modules/angular2/bundles/angular2.dev.js',
    'node_modules/angular2/bundles/router.dev.js',
    'node_modules/**/*.js',
    'node_modules/**/*.css'
    ])
    .pipe(gulp.dest('dist/node_modules'))
    });

    // copy static assets - i.e. non TypeScript compiled source
    gulp.task('copy:assets', ['clean'], function() {
    return gulp.src(['app/**/*', 'index.html', 'systemjs.config.js', '!app/**/*.ts'], { base : './' })
    .pipe(gulp.dest('dist'))
    });

    gulp.task('build', ['compile']);
    gulp.task('default', ['build']);

    Continue reading...

Compartilhe esta Página