1 | #! /usr/bin/env node
|
2 |
|
3 | const {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 |
|
10 | const staticFolder = process.env.CANON_STATIC_FOLDER || "static";
|
11 | const staticPath = path.join(process.cwd(), staticFolder);
|
12 |
|
13 | shell.rm("-rf", path.join(staticPath, "assets/"));
|
14 | shell.mkdir("-p", path.join(staticPath, "assets/"));
|
15 |
|
16 | title("Bundling Production Webpack", "🔷");
|
17 | const webpackDevConfig = require(path.join(__dirname, "../webpack/prod.js"));
|
18 | webpack(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 | });
|