Added BrowserSync
This commit is contained in:
@@ -12,3 +12,4 @@ deploy-*.sh
|
|||||||
assets/css/**/*.min.css*
|
assets/css/**/*.min.css*
|
||||||
assets/css-old/**/*.min.css*
|
assets/css-old/**/*.min.css*
|
||||||
components/**/*.min.css*
|
components/**/*.min.css*
|
||||||
|
config.js
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
"mode": "production"
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
"mode": "development"
|
||||||
|
}
|
||||||
Generated
+2477
File diff suppressed because it is too large
Load Diff
+6
-1
@@ -1,11 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "axe-web-component",
|
"name": "axe-web-component",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {},
|
"scripts": {
|
||||||
|
"start": "NODE_ENV=production node server.js",
|
||||||
|
"dev": "NODE_ENV=development node server.js"
|
||||||
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"browser-sync": "^2.27.9",
|
||||||
|
"config": "^3.3.7",
|
||||||
"express": "^4.17.3",
|
"express": "^4.17.3",
|
||||||
"express-handlebars": "^6.0.4",
|
"express-handlebars": "^6.0.4",
|
||||||
"fs-extra": "^10.0.1"
|
"fs-extra": "^10.0.1"
|
||||||
|
|||||||
@@ -3,17 +3,31 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {create} from 'express-handlebars';
|
import {create} from 'express-handlebars';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import browserSync from 'browser-sync';
|
||||||
|
import config from 'config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
|
|
||||||
|
const isDev = config.get('mode') === 'development';
|
||||||
|
const projectDir = isDev ? '.' : './node_modules/axe-web-component';
|
||||||
|
console.log(isDev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init server
|
||||||
|
*/
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const hbs = create({
|
const hbs = create({
|
||||||
extname: '.hbs', defaultLayout: false,
|
extname: '.hbs', defaultLayout: false,
|
||||||
partialsDir: ['.'],
|
partialsDir: ['.'],
|
||||||
})
|
});
|
||||||
|
|
||||||
app.engine('.hbs', hbs.engine);
|
app.engine('.hbs', hbs.engine);
|
||||||
app.set('view engine', '.hbs');
|
app.set('view engine', '.hbs');
|
||||||
app.set('views', './layouts');
|
app.set('views', projectDir + '/layouts');
|
||||||
|
|
||||||
app.get('/', async (req, res) => {
|
app.get('/', async (req, res) => {
|
||||||
const jsonFileName = (req.query.data) ? req.query.data : 'default';
|
const jsonFileName = (req.query.data) ? req.query.data : 'default';
|
||||||
@@ -24,16 +38,47 @@ app.get('/', async (req, res) => {
|
|||||||
|
|
||||||
app.use(express.static('src'));
|
app.use(express.static('src'));
|
||||||
|
|
||||||
const PORT = 3002;
|
const listener = app.listen(0, () => {
|
||||||
app.listen(PORT, () => {
|
const PORT = listener.address().port;
|
||||||
|
|
||||||
console.log(`The web server has started on port ${PORT}`);
|
console.log(`The web server has started on port ${PORT}`);
|
||||||
|
|
||||||
|
const bs = browserSync.create();
|
||||||
|
|
||||||
|
bs.watch("src/**/*.js", function (event, file) {
|
||||||
|
if (isDev) {
|
||||||
|
console.log(event, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.reload("*.js");
|
||||||
|
});
|
||||||
|
|
||||||
|
bs.watch("src/**/*.css", function (event, file) {
|
||||||
|
if (isDev) {
|
||||||
|
console.log(event, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.reload("*.css");
|
||||||
|
});
|
||||||
|
|
||||||
|
bs.watch("src/**/*.hbs", function (event, file) {
|
||||||
|
if (isDev) {
|
||||||
|
console.log(event, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
bs.init({
|
||||||
|
proxy: `http://localhost:${PORT}`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
//
|
||||||
// Add Gulp for CSS/JS Styling
|
// Add Gulp for CSS/JS Styling
|
||||||
// Add Browsersync that will refresh the page on changes
|
// [v] Add Browsersync that will refresh the page on changes
|
||||||
// Top Panel with options to switch data (select input)
|
//
|
||||||
// Options to resize the page and test Responsiveness (select input)
|
// Breakpoints and data options will come from backend server.
|
||||||
|
// - Top Panel with options to switch data (select input)
|
||||||
|
// - Options to resize the page and test Responsiveness (select input)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user