Skip to content

Instantly share code, notes, and snippets.

@chcepe
Created February 18, 2019 12:39
Show Gist options
  • Save chcepe/fe187d2a65d6cbd780e475c6f47ec781 to your computer and use it in GitHub Desktop.
Save chcepe/fe187d2a65d6cbd780e475c6f47ec781 to your computer and use it in GitHub Desktop.
Script to compress Next.js build folder with web.config
const stat = require("fs").statSync;
const AdmZip = require("adm-zip");
newArchive(`deploy.zip`, [
".next",
"static",
"next.config.js",
"package-lock.json",
"package.json",
"server.js",
"web.config"
]);
function newArchive(zipFileName, pathNames) {
const zip = new AdmZip();
pathNames.forEach(path => {
const p = stat(path);
if (p.isFile()) {
zip.addLocalFile(path);
} else if (p.isDirectory()) {
zip.addLocalFolder(path, path);
}
});
zip.writeZip(zipFileName);
}
{
"name": "create-next-example-app",
"scripts": {
"dev": "next",
"build": "next build && node deploy.js",
"start": "next start",
"export": "next export"
},
"dependencies": {
"adm-zip": "^0.4.13",
"express": "^4.16.4",
"next": "^8.0.0",
"react": "16.7.0",
"react-dom": "16.7.0"
}
}
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation batch="false" />
</system.web>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment