1

as long as i keep everything in my rootfolder, leveraging tsc/npm scripts and lite-server with JIT compiling works perfectly fine

i.e.

project_folder
bs-config.js
index.html //with ref to
src/
  main.ts
  //main.js
  //main.js.map
  app/
    app.module.ts
    //etc..
    components/
      foo/
      foo.component.ts       

bs-config for handling this:

var proxy = require('http-proxy-middleware');

var myProxy= proxy('/path', {
  target: 'http://xxxx/path',
  changeOrigin: true
});

module.exports = {
  port: 3000,
  files: ["./src/**/*.{html,htm,css,js}"],
  open: false,
  logLevel: "info",
  server: {
    index: "index.html"
    middleware: {
      1: myProxy
    }
  }
};

as a new requirement from a colleague this should changed to a more "gulp way" of development, with a classic dist folder, where compiled .js files should go

trying to implement this with only standard npm scripts i just added "outDir": "./dist" to tsconfig

big problem is, as soon as i change baseDir of bs-config, i can no longer access node_modules, as lite-server apparently cant serve things outside of its baseDir?

specifically i cant get past getting my minimal node-libs from index.html, e.g.

<script src="node_modules/core-js/client/library.min.js"></script>
<!-- ../node_modules cant get resolved -->

the fix provided here, does not work for me: lite-server does not load scripts from parent directory in Angular 2 app

Community
  • 1
  • 1
longbow
  • 1,593
  • 1
  • 16
  • 39

1 Answers1

0

When you set the server.baseDir route, you also need to configure the server.routes option in order to be able to access paths from the parent folder of baseDir. Like this:

{
    "server": { 
        "baseDir": "./src",
        "routes": { "/node_modules": "node_modules" }
    }
}

Then in your files inside ./src you'd change the node_modules/foo paths to ../node_modules/foo.

mrrrow
  • 98
  • 3
  • 9