My dev server is running on node live-server. My prod will be a LAMP server.
I have normalize.css
inside my node_modules server.
In my index.html
I have
<link rel="stylesheet" href="/node_modules/normalize.css">
<link rel="stylesheet" href="css/styles.css">
I don't want files linked to node_modules
directory.
I want something like
<link rel="stylesheet" href="css/normalize.css">
Is this doable? I have lot of other css and js files like this.
Update 1
Let me clarify, this app is not a node app nor a php app, It has only html, css and js files. Everything runs on client side, But.. we want to leverage the latest client side dev tools for JS and CSS and upload the final build to prod server.
Code for serving HTML and CSS files in Express use(express. static(path. join(__dirname,'CSS')); //This command is used to serve the CSS files which are kept in the CSS folder from the working directory.
Conclusion: With simple File IO operations we can read HTML file in Node. js and by using simple modules, we can send a HTML response back to client.
There are lots of possible solutions. I can suggest using a task runner(gulp) which will copy these static files to a public directory like dist/assets
.
Install gulp on your machine
npm install --save-dev gulp
Create a gulpfile.js
file in your root directory with following code.
var gulp = require('gulp');
gulp.task('default', function () {
gulp.src('/node_modules/normalize.css')
.pipe(gulp.dest('./dist/assets'));
});
Run gulp
gulp
Update your index.html
as below
<link rel="stylesheet" href="/dist/assets/normalize.css">
Please go through the documentation of Gulp for more information
You can also try Grunt or Webpack
You could use Webpack
for bundling, which would copy css resources to the dist and replace references to it. It doesn't support html files as entry points though, so you'd need to work around that by probably using html-webpack-plugin
.
anyway, as was mentioned by others - server decisions are weird.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With