diff --git a/.gitignore b/.gitignore index b5645ae..89d83f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules/ .vscode/ dist/ -package-lock.json -main.html \ No newline at end of file +package-lock.json \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index b8aafad..ffbd216 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,36 +3,26 @@ const browserSyncInstance = require('browser-sync').create() const sass = require('sass') const gulpSass = require('gulp-sass')(sass) -// Dynamic import of gulp-autoprefixer -async function loadAutoprefixer() { - const { default: autoprefixer } = await import('gulp-autoprefixer') - return autoprefixer -} - // Compile Sass into CSS & auto-inject into browsers gulp.task('sass', async function () { - const autoprefixer = await loadAutoprefixer(); // Load autoprefixer dynamically return gulp.src('src/scss/**/*.scss') .pipe(gulpSass().on('error', gulpSass.logError)) // Compile SCSS with error logging - .pipe(autoprefixer({ - overrideBrowserslist: ['last 2 versions'], - cascade: false - })) + .pipe(gulp.dest('dist/css')) .pipe(browserSyncInstance.stream()); // Inject CSS changes into the browser }) // Start a local server with BrowserSync & watch files for changes -gulp.task('serve', function () { +gulp.task('serve', () => { browserSyncInstance.init({ - server: './src' // Serve from the root directory (or specify a different folder) - }); + proxy: 'http://localhost:3002', + files: ['src/**/*.html', 'dist/css/*.css', 'src/scripts/**/*.js'], + port: 3000 + }) - gulp.watch('src/scss/**/*.scss', gulp.series('sass')); // Watch for Sass changes - gulp.watch('*.html').on('change', browserSyncInstance.reload); // Watch for HTML changes - gulp.watch('dist/css/**/*.css').on('change', browserSyncInstance.reload); // Watch for CSS changes + gulp.watch('src/scss/**/*.scss', gulp.series('sass')) }) // Default task: compile Sass, autoprefix, and start the server -gulp.task('default', gulp.series('sass', 'serve')); \ No newline at end of file +gulp.task('default', gulp.series('sass', 'serve')) \ No newline at end of file diff --git a/package.json b/package.json index 69f8280..b8fb200 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "commonjs", "main": "index.js", "scripts": { - "start": "gulp" + "start": "concurrently \"gulp\" \"node server.js\"" }, "author": "bckelley", "license": "CC BY-NC-SA 4.0", @@ -13,10 +13,15 @@ "node": ">=18.8.0" }, "devDependencies": { - "browser-sync": "^2.18.13", + "browser-sync": "^3.0.2", + "concurrently": "^9.0.0", "gulp": "^5.0.0", "gulp-autoprefixer": "^9.0.0", "gulp-sass": "^5.1.0", "sass": "^1.56.0" + }, + "dependencies": { + "express": "^4.19.2", + "http-proxy-middleware": "^3.0.2" } } diff --git a/server.js b/server.js new file mode 100644 index 0000000..dd78b13 --- /dev/null +++ b/server.js @@ -0,0 +1,38 @@ +const express = require('express') +const fs = require('fs') +const path = require('path') +const { createProxyMiddleware } = require('http-proxy-middleware'); + +const app = express() +const port = '3002' + +app.use('/dist/css', express.static(path.join(__dirname, 'dist/css'))) + +app.use('/src/edits', express.static(path.join(__dirname, 'src/edits'))) + +app.get('/', (req, res) => { + res.sendFile(path.join(__dirname, 'src', 'index.html')); +}) + +app.get('/api/files', (req, res) => { + const dirPath = path.join(__dirname, 'src/edits/') + const exts = '.html' + + fs.readdir(dirPath, (err, files) => { + if (err) { + console.error("Error reading directory", err) + return res.status(500).json({ error: "Could not read the directory" }) + } + + res.json({ files: files }) + }) +}) + +app.use('/api', createProxyMiddleware({ + target: 'http://localhost:3000', + changeOrigin: true +})) + +app.listen(port, () => { + console.log(`Server is running on http://localhost:${port}`) +}) \ No newline at end of file diff --git a/src/edits/main.html b/src/edits/main.html new file mode 100644 index 0000000..248b9e6 --- /dev/null +++ b/src/edits/main.html @@ -0,0 +1,40 @@ + + +
+ + + + ++ Lorem, ipsum dolor sit amet consectetur adipisicing elit. Est + eligendi tempore atque laborum. Quisquam nemo at non. Corrupti, + vitae dolore. Lorem voluptate Lorem cupidatat in cillum quis reprehenderit minim aliquip. Ullamco tempor adipisicing velit id amet eiusmod ullamco pariatur magna dolore. Eiusmod id in ut aute velit reprehenderit est dolore dolor. +
+ Learn More + Sign Up +
+ Edit the scss/style.scss file and it will automatically compile into css/style.css
+Edit the scss/style.scss file and it will automatically compile into css/style.css
+ +