UNPKG

1.13 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3const {title} = require("./logging.js"),
4 babel = require("@babel/core"),
5 chalk = require("chalk"),
6 path = require("path"),
7 shell = require("shelljs"),
8 webpack = require("webpack");
9
10const staticFolder = process.env.CANON_STATIC_FOLDER || "static";
11const staticPath = path.join(process.cwd(), staticFolder);
12
13shell.rm("-rf", path.join(staticPath, "assets/"));
14shell.mkdir("-p", path.join(staticPath, "assets/"));
15
16title("Bundling Production Webpack", "🔷");
17const webpackDevConfig = require(path.join(__dirname, "../webpack/prod.js"));
18webpack(webpackDevConfig, () => {
19
20 title("Generating index.js", "📒");
21 let {code} = babel.transformFileSync(`${__dirname}/server/index.js`, {
22 ignore: [staticFolder],
23 presets: [
24 ["@babel/preset-env", {targets: {node: "current"}}]
25 ]
26 });
27
28 code = code
29 .replace(/process\.cwd\(\)/g, "__dirname")
30 .replace("process.env.NODE_ENV", "\"production\"");
31
32 new shell.ShellString(code).to(`${process.cwd()}/index.js`);
33 shell.echo(`File created: ${chalk.bold(`${process.cwd()}/index.js\n`)}`);
34 shell.exit(0);
35
36});