Gisle Aune
6 years ago
10 changed files with 110 additions and 123 deletions
-
1.gitignore
-
4Dockerfile
-
66build.js
-
15builder.js
-
31marko-config.js
-
2marko/page/layout.marko
-
11package-lock.json
-
2package.json
-
23routes/globalcss.js
-
60server.js
@ -1,4 +1,5 @@ |
|||
*.marko.js |
|||
*.prebuild.json |
|||
/node_modules |
|||
npm-debug.log |
|||
/.cache |
|||
|
@ -1,53 +1,27 @@ |
|||
const build = require("./builder") |
|||
const prebuild = require("@marko/prebuild"); |
|||
|
|||
// Setup global environment
|
|||
require("marko/node-require").install() |
|||
require("es6-promise").polyfill() |
|||
const config = require("./marko-config") |
|||
config.loadPrebuild = false |
|||
|
|||
// Configure lasso
|
|||
require("lasso").configure({ |
|||
plugins: [ |
|||
"lasso-marko", |
|||
"lasso-less", |
|||
], |
|||
outputDir: "./.static", |
|||
bundlingEnabled: true, |
|||
minify: true, |
|||
fingerprintsEnabled: true, |
|||
|
|||
require: { |
|||
builtins: { |
|||
fs: require.resolve("empty-module"), |
|||
}, |
|||
|
|||
transforms: [ |
|||
{ |
|||
transform: "lasso-babel-transform", |
|||
config: { |
|||
extensions: [".js", ".es6"], // Enabled file extensions. Default: [".js", ".es6"]
|
|||
babelOptions: { |
|||
presets: [ "es2015" ] |
|||
} |
|||
} |
|||
} |
|||
prebuild.run({ |
|||
config: config, |
|||
pages: [ // List of pages to prebuild.
|
|||
"./marko/page/story/list.marko", |
|||
"./marko/page/story/tag-list.marko", |
|||
"./marko/page/logs/list.marko", |
|||
"./marko/page/data/channels.marko", |
|||
"./marko/page/data/characters.marko", |
|||
"./marko/page/story-content/view.marko", |
|||
"./marko/page/logs-content/view.marko", |
|||
] |
|||
} |
|||
}) |
|||
}).then(lassoPrebuildResult => { |
|||
const builds = lassoPrebuildResult._buildsByPath |
|||
|
|||
// Render templates
|
|||
async function buildAll() { |
|||
await build("./marko/page/story/list.marko") |
|||
await build("./marko/page/story/tag-list.marko", {tags: []}) |
|||
await build("./marko/page/logs/list.marko") |
|||
await build("./marko/page/data/channels.marko", {channels: [], user: {}}) |
|||
await build("./marko/page/data/characters.marko", {characters: [], user: {}}) |
|||
await build("./marko/page/story-content/view.marko", {story: {chapters: []}}) |
|||
await build("./marko/page/logs-content/view.marko", {log: {posts: [], channel: {}}}) |
|||
for (const key in builds) { |
|||
if (!builds.hasOwnProperty(key)) { |
|||
continue |
|||
} |
|||
|
|||
buildAll().then(() => { |
|||
console.log("Done!") |
|||
}).catch(err => { |
|||
console.error(err) |
|||
process.exit(1) |
|||
console.log("Built", key) |
|||
} |
|||
}) |
@ -1,15 +0,0 @@ |
|||
module.exports = function build(path, data) { |
|||
console.log("Building", path) |
|||
|
|||
return new Promise((resolve, reject) => { |
|||
const render = require(path).render(data) |
|||
render.once("error", err => reject) |
|||
|
|||
const interval = setInterval(() => { |
|||
if (render._remaining === 0) { |
|||
clearInterval(interval) |
|||
resolve() |
|||
} |
|||
}, 500) |
|||
}) |
|||
} |
@ -0,0 +1,31 @@ |
|||
const isProduction = process.env.NODE_ENV === "production" |
|||
|
|||
module.exports = { |
|||
plugins: [ |
|||
"lasso-marko", |
|||
"lasso-less", |
|||
], |
|||
outputDir: "./.static", // Place all generated JS/CSS/etc. files into the "static" dir
|
|||
bundlingEnabled: isProduction, // Only enable bundling in production
|
|||
minify: isProduction, // Only minify JS and CSS code in production
|
|||
fingerprintsEnabled: isProduction, // Only add fingerprints to URLs in production
|
|||
loadPrebuild: isProduction, // Only load prebuilt stuff in prod.
|
|||
|
|||
require: { |
|||
builtins: { |
|||
fs: require.resolve("empty-module"), |
|||
}, |
|||
|
|||
transforms: isProduction ? [ |
|||
{ |
|||
transform: "lasso-babel-transform", |
|||
config: { |
|||
extensions: [".js", ".es6"], // Enabled file extensions. Default: [".js", ".es6"]
|
|||
babelOptions: { |
|||
presets: [ "es2015" ] |
|||
} |
|||
} |
|||
} |
|||
] : null |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
const fs = require("fs") |
|||
const express = require("express") |
|||
const less = require("less") |
|||
|
|||
const router = express.Router() |
|||
|
|||
let lessData = "" |
|||
let data = "" |
|||
for (const name of fs.readdirSync("./marko/global/", "utf8")) { |
|||
data += fs.readFileSync("./marko/global/"+name, {encoding:"utf8"}) + "\n\n" |
|||
} |
|||
data = less.render(data, (err, output) => { |
|||
if (err == null) { |
|||
lessData = output.css |
|||
} |
|||
}) |
|||
|
|||
router.get("/", (req, res) => { |
|||
res.contentType("text/css").end(lessData) |
|||
}) |
|||
|
|||
|
|||
module.exports = router |
Write
Preview
Loading…
Cancel
Save
Reference in new issue