Add server config, move plugin file

This commit is contained in:
Michael Jackson 2018-05-17 10:10:33 -07:00
parent 041d0c407f
commit da06a5b97f
6 changed files with 29 additions and 10 deletions

View File

@ -1,9 +1,9 @@
const path = require("path");
const throng = require("throng");
const createServer = require("./server/createServer");
const createDevServer = require("./server/createDevServer");
const port = parseInt(process.env.PORT, 10) || 5000;
const config = require("./server/config");
function startServer(id) {
const server =
@ -15,11 +15,15 @@ function startServer(id) {
: createDevServer(
path.resolve(__dirname, "public"),
require("./webpack.config"),
`http://localhost:${port}`
config.origin
);
server.listen(port, () => {
console.log("Server #%s listening on port %s, Ctrl+C to stop", id, port);
server.listen(config.port, () => {
console.log(
"Server #%s listening on port %s, Ctrl+C to stop",
id,
config.port
);
});
}

View File

@ -7,7 +7,7 @@ const IndexPage = require("../components/IndexPage");
const renderPage = require("../utils/renderPage");
const getMetadata = require("../utils/getMetadata");
const getFileContentType = require("../utils/getFileContentType");
const unpkgRewrite = require("../utils/unpkgRewriteBabelPlugin");
const unpkgRewrite = require("../plugins/unpkgRewrite");
const getEntries = require("../utils/getEntries");
/**

6
server/config.js Normal file
View File

@ -0,0 +1,6 @@
exports.port = parseInt(process.env.PORT, 10) || 5000;
exports.origin =
process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test"
? "https://unpkg.com"
: `http://localhost:${exports.port}`;

View File

@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}

View File

@ -1,5 +1,5 @@
const babel = require("babel-core");
const unpkgRewrite = require("../unpkgRewriteBabelPlugin");
const unpkgRewrite = require("../unpkgRewrite");
const testCases = [
{

View File

@ -1,9 +1,11 @@
const URL = require("whatwg-url");
const warning = require("warning");
const config = require("../config");
const bareIdentifierFormat = /^((?:@[^\/]+\/)?[^\/]+)(\/.*)?$/;
function unpkgRewriteBabelPlugin(dependencies = {}) {
function unpkgRewrite(dependencies = {}) {
return {
inherits: require("babel-plugin-syntax-export-extensions"),
@ -34,11 +36,13 @@ function unpkgRewriteBabelPlugin(dependencies = {}) {
const version = dependencies[packageName] || "latest";
path.node.source.value = `https://unpkg.com/${packageName}@${version}${file}?module`;
path.node.source.value = `${
config.origin
}/${packageName}@${version}${file}?module`;
}
}
}
};
}
module.exports = unpkgRewriteBabelPlugin;
module.exports = unpkgRewrite;