Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser-sync - serve "node_modules" out of "src" directory

I'm using browsersync via lite-server, and have the following configuration:

{
    "port": 8000,
    "files": [
        "./src/**/*.{html,htm,css,js}"
    ],
    "server": {
        "baseDir": "./src",
        "routes": {
            "node_modules": "../node_modules" <--- Attempt to serve node_modules
        }
    }
}

Project layout is like this:

node_modules src |-app |-index.html |-systemjs.config.js package.json bs-config.json

The problem is that inside index.html any reference like <script src="node_modules/....js"> fails with a 404.

How can I serve paths outside of .src directory?

like image 942
Cristian E. Avatar asked Sep 02 '16 23:09

Cristian E.


2 Answers

You can expose whole project folder by adding one more element to baseDir as Edvin mentioned.

But it would be better if you will expose only /node_modules using routes:

module.exports = {
    server : {
        baseDir : './dist',
        routes : {
            '/vendor' : './node_modules'
        }
    }
}
like image 118
Dmitry Lukichev Avatar answered Oct 22 '22 09:10

Dmitry Lukichev


You can use multiple directory in baseDir config:

{
    "server": {
        "baseDir": ["./", "./src" ]
    }
}
like image 28
Rafal Sujak Avatar answered Oct 22 '22 08:10

Rafal Sujak