You do not need to have any script tags or style sheets in the header if you are using webpack with this webpack.config.js:
module.exports = { entry: "./calendar.js", output: { filename: "bundle.js" }, module: { loaders: [ { test: [/.js?$/], exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015'] } }, { test: /\.css$/, loader: 'style-loader!css-loader' } ] } };
And you need npm to install babel. And if you want webpack to process your css files for you, you can npm set the bootloader and css loader style. Here is my .json package:
{ "name": "full_calendar_demo", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "babel-core": "^6.18.2", "babel-loader": "^6.2.8", "babel-preset-es2015": "^6.18.0", "css-loader": "^0.26.1", "fullcalendar": "^3.1.0", "jquery": "^3.1.1", "moment": "^2.17.1", "style-loader": "^0.13.1", "webpack": "^1.13.3" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }
Then my index.html file doesn't need script tags:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src='bundle.js'></script> </head> <body> <div id="calendar"></div> </body> </html>
And I just include packages in my javascript file:
import $ from 'jquery' import 'fullcalendar' import 'fullcalendar/dist/fullcalendar.css' $(document).ready(() => { $('#calendar').fullCalendar() })
I'm still looking for a way to clear the import method of the css file, but at least I don't have the html file that looks like this:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel='stylesheet' href='node_modules/fullcalendar/dist/fullcalendar.css' /> <script src='node_modules/jquery/dist/jquery.min.js'></script> <script src='node_modules/moment/min/moment.min.js'></script> <script src='node_modules/fullcalendar/dist/fullcalendar.js'></script> <script src='entry.js'></script> </head> <body> <div id="calendar"></div> </body> </html>
Please let me know how to include the css file more cleanly.