mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-05 12:57:33 +03:00
Wire through StaticRequests end-to-end.
This commit is contained in:
parent
f8f5504423
commit
c04b72c5c2
@ -143,7 +143,7 @@ view siteMetadata page =
|
||||
|
||||
_ ->
|
||||
StaticHttp.withData "https://api.github.com/repos/dillonkearns/elm-pages-starter"
|
||||
(Decode.succeed 987)
|
||||
(Decode.field "stargazers_count" Decode.int)
|
||||
(\staticData ->
|
||||
{ view =
|
||||
\model viewForPage ->
|
||||
|
@ -20,7 +20,10 @@ function unpackFile(filePath) {
|
||||
}
|
||||
|
||||
module.exports = class AddFilesPlugin {
|
||||
constructor() {}
|
||||
constructor(data) {
|
||||
// console.log("@@@@@@@@@@ data", data);
|
||||
this.pagesWithRequests = data;
|
||||
}
|
||||
apply(compiler) {
|
||||
compiler.hooks.emit.tap("AddFilesPlugin", compilation => {
|
||||
const files = glob.sync("content/**/*.*", {}).map(unpackFile);
|
||||
@ -30,11 +33,25 @@ module.exports = class AddFilesPlugin {
|
||||
// but I found the example code for it here:
|
||||
// https://github.com/jantimon/html-webpack-plugin/blob/35a154186501fba3ecddb819b6f632556d37a58f/index.js#L470-L478
|
||||
|
||||
console.log("@@@@@@ file.baseRoute", file.baseRoute);
|
||||
|
||||
// console.log(
|
||||
// "@@@@@@ lookup",
|
||||
// this.pagesWithRequests[`/${file.baseRoute}`]
|
||||
// );
|
||||
const staticRequests = this.pagesWithRequests[`/${file.baseRoute}`];
|
||||
|
||||
const jsonPayload = staticRequests
|
||||
? Object.entries(staticRequests)[0][1]
|
||||
: "null";
|
||||
console.log("@@@@@ payload", jsonPayload);
|
||||
|
||||
const filename = path.join(file.baseRoute, "content.json");
|
||||
compilation.fileDependencies.add(filename);
|
||||
const rawContents = JSON.stringify({
|
||||
body: file.content,
|
||||
staticData: { stargazers_count: 85 }
|
||||
// staticData: { stargazers_count: 85 }
|
||||
staticData: JSON.parse(jsonPayload)
|
||||
});
|
||||
|
||||
compilation.assets[filename] = {
|
||||
|
@ -16,10 +16,11 @@ const ClosurePlugin = require("closure-webpack-plugin");
|
||||
const readline = require("readline");
|
||||
|
||||
module.exports = { start, run };
|
||||
function start({ routes, debug, manifestConfig }) {
|
||||
function start({ routes, debug, manifestConfig, routesWithRequests }) {
|
||||
const config = webpackOptions(false, routes, {
|
||||
debug,
|
||||
manifestConfig
|
||||
manifestConfig,
|
||||
routesWithRequests
|
||||
});
|
||||
|
||||
const compiler = webpack(config);
|
||||
@ -58,41 +59,45 @@ function start({ routes, debug, manifestConfig }) {
|
||||
// app.use(express.static(__dirname + "/path-to-static-folder"));
|
||||
}
|
||||
|
||||
function run({ routes, manifestConfig }, callback) {
|
||||
webpack(webpackOptions(true, routes, { debug: false, manifestConfig })).run(
|
||||
(err, stats) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
console.log(
|
||||
stats.toString({
|
||||
chunks: false, // Makes the build much quieter
|
||||
colors: true, // Shows colors in the console
|
||||
// copied from `'minimal'`
|
||||
all: false,
|
||||
modules: false,
|
||||
performance: true,
|
||||
timings: false,
|
||||
outputPath: true,
|
||||
maxModules: 0,
|
||||
errors: true,
|
||||
warnings: true,
|
||||
// our additional options
|
||||
moduleTrace: false,
|
||||
errorDetails: false
|
||||
})
|
||||
);
|
||||
|
||||
const duration = roundToOneDecimal(
|
||||
(stats.endTime - stats.startTime) / 1000
|
||||
);
|
||||
console.log(`Duration: ${duration}s`);
|
||||
function run({ routes, manifestConfig, routesWithRequests }, callback) {
|
||||
webpack(
|
||||
webpackOptions(true, routes, {
|
||||
debug: false,
|
||||
manifestConfig,
|
||||
routesWithRequests
|
||||
})
|
||||
).run((err, stats) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
);
|
||||
|
||||
console.log(
|
||||
stats.toString({
|
||||
chunks: false, // Makes the build much quieter
|
||||
colors: true, // Shows colors in the console
|
||||
// copied from `'minimal'`
|
||||
all: false,
|
||||
modules: false,
|
||||
performance: true,
|
||||
timings: false,
|
||||
outputPath: true,
|
||||
maxModules: 0,
|
||||
errors: true,
|
||||
warnings: true,
|
||||
// our additional options
|
||||
moduleTrace: false,
|
||||
errorDetails: false
|
||||
})
|
||||
);
|
||||
|
||||
const duration = roundToOneDecimal(
|
||||
(stats.endTime - stats.startTime) / 1000
|
||||
);
|
||||
console.log(`Duration: ${duration}s`);
|
||||
});
|
||||
}
|
||||
|
||||
function roundToOneDecimal(n) {
|
||||
@ -104,12 +109,16 @@ function printProgress(progress, message) {
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(`${progress} ${message}`);
|
||||
}
|
||||
function webpackOptions(production, routes, { debug, manifestConfig }) {
|
||||
function webpackOptions(
|
||||
production,
|
||||
routes,
|
||||
{ debug, manifestConfig, routesWithRequests }
|
||||
) {
|
||||
const common = {
|
||||
entry: "./index.js",
|
||||
mode: production ? "production" : "development",
|
||||
plugins: [
|
||||
new AddFilesPlugin(),
|
||||
new AddFilesPlugin(routesWithRequests),
|
||||
new CopyPlugin([
|
||||
{
|
||||
from: "static/**/*",
|
||||
|
@ -93,7 +93,8 @@ function run() {
|
||||
develop.start({
|
||||
routes,
|
||||
debug: contents.debug,
|
||||
manifestConfig: payload.manifest
|
||||
manifestConfig: payload.manifest,
|
||||
routesWithRequests: payload.pages
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -104,7 +105,8 @@ function run() {
|
||||
develop.run(
|
||||
{
|
||||
routes,
|
||||
manifestConfig: payload.manifest
|
||||
manifestConfig: payload.manifest,
|
||||
routesWithRequests: payload.pages
|
||||
},
|
||||
() => {}
|
||||
);
|
||||
|
@ -384,7 +384,7 @@ update siteMetadata config msg model =
|
||||
}
|
||||
|
||||
Err error ->
|
||||
Debug.todo "TODO handle error"
|
||||
Debug.todo (Debug.toString error)
|
||||
|
||||
Err errors ->
|
||||
Debug.todo "TODO handle error"
|
||||
@ -419,7 +419,7 @@ staticResponsesUpdate newEntry staticResponses =
|
||||
case entry of
|
||||
NotFetched (StaticHttpRequest.Request { url }) ->
|
||||
if newEntry.url == url then
|
||||
SuccessfullyFetched (StaticHttpRequest.Request { url = url }) ""
|
||||
SuccessfullyFetched (StaticHttpRequest.Request { url = url }) newEntry.response
|
||||
|
||||
else
|
||||
entry
|
||||
|
Loading…
Reference in New Issue
Block a user