nickjj / build-a-saas-app-with-flask

Learn how to build a production ready web app with Flask and Docker.
https://buildasaasappwithflask.com
MIT License
954 stars 185 forks source link

Adding Custom CSS and JS #35

Closed elie-h closed 8 years ago

elie-h commented 8 years ago

What's the best way on adding custom .css and .js files, I added my files into assets, but they don't seem to be in effect.

nickjj commented 8 years ago

When adding new files you would have to restart the webpack dev server.

elie-h commented 8 years ago

So if I add a .js file into catwatch/assets/scripts, Its contents should be available in all templates after restarting & rebuilding assets correct?

Also where is the javascript called? I can't find any javascript in any of the jinja2 templates.

nickjj commented 8 years ago

It's bundled into a single file and included at the footer of the layout: https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/catwatch/templates/layouts/base.jinja2#L43

All of the JS is in here: https://github.com/nickjj/build-a-saas-app-with-flask/tree/master/catwatch/assets/scripts

All of it is handled through webpack here: https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/config/webpack.config.js

elie-h commented 8 years ago

I added custom CSS and JS files. The css has taken effect, but the JS file doesn't seem to have an effect. I don't think it's being used by webpack. Do I have to import it or register it anywhere?

nickjj commented 8 years ago

What does the JS do?

You'd have to add it to this list: https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/config/webpack.config.js#L54-L56

elie-h commented 8 years ago

Just the JS file for Bootstrap Switch: http://www.bootstrap-switch.org/ If I load the script manually it works fine in the browser.

I've done the following in webpack.config.js:

app_js: [ 'bootstrap-switch', path.join(contextRoot, assets.scripts.path, 'entry.js') ],

But that doesn't seem correct.

nickjj commented 8 years ago

Oh, it's a vendor JS.

In that case, follow this example by basically copy/pasting that and changing the file name: https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/config/webpack.config.js#L63-L64

It's the same situation where I'm using a third party JS library. It has CSS too. Just place the files in the same directories as the eonasdan-bootstrap-datetimepicker lib in the webpack config.

treldor commented 8 years ago

wrong three

elie-h commented 8 years ago

?? Adding to Vendor worked. Closed.