mirror of
https://github.com/dillonkearns/elm-pages.git
synced 2024-09-11 09:05:28 +03:00
Run terser inline instead of through npx in elm-pages-beta build command.
This commit is contained in:
parent
2d19e65daf
commit
d702764be2
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
// @ts-check
|
||||
|
||||
const cliVersion = require("../../package.json").version;
|
||||
const indexTemplate = require("./index-template.js");
|
||||
@ -10,6 +11,7 @@ const exec = util.promisify(require("child_process").exec);
|
||||
const spawnCallback = require("child_process").spawn;
|
||||
const codegen = require("./codegen.js");
|
||||
const generateManifest = require("./generate-manifest.js");
|
||||
const terser = require("terser");
|
||||
|
||||
const DIR_PATH = path.join(process.cwd());
|
||||
const OUTPUT_FILE_NAME = "elm.js";
|
||||
@ -107,14 +109,13 @@ function cleanRoute(route) {
|
||||
async function elmToEsm(elmPath) {
|
||||
const elmEs3 = await fs.readFile(elmPath, "utf8");
|
||||
|
||||
const elmEsm =
|
||||
return (
|
||||
"\n" +
|
||||
"const scope = {};\n" +
|
||||
elmEs3.replace("}(this));", "}(scope));") +
|
||||
"export const { Elm } = scope;\n" +
|
||||
"\n";
|
||||
|
||||
await fs.writeFile(elmPath, elmEsm);
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,8 +160,9 @@ async function compileElm() {
|
||||
const outputPath = `dist/elm.js`;
|
||||
await spawnElmMake("src/Main.elm", outputPath);
|
||||
|
||||
await elmToEsm(path.join(process.cwd(), outputPath));
|
||||
runTerser(outputPath);
|
||||
const elmEsmContent = await elmToEsm(path.join(process.cwd(), outputPath));
|
||||
const elmFileOutput = await runTerserNew(elmEsmContent);
|
||||
await fs.writeFile(path.join(process.cwd(), outputPath), elmFileOutput);
|
||||
}
|
||||
|
||||
function spawnElmMake(elmEntrypointPath, outputPath, cwd) {
|
||||
@ -194,12 +196,46 @@ function spawnElmMake(elmEntrypointPath, outputPath, cwd) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @param {string} fileContents
|
||||
* @returns string
|
||||
*/
|
||||
async function runTerser(filePath) {
|
||||
await shellCommand(
|
||||
`npx terser ${filePath} --module --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | npx terser --module --mangle --output=${filePath}`
|
||||
);
|
||||
async function runTerserNew(fileContents) {
|
||||
const minifiedElm = await terser.minify(fileContents, {
|
||||
ecma: 5,
|
||||
|
||||
module: true,
|
||||
compress: {
|
||||
pure_funcs: [
|
||||
"F2",
|
||||
"F3",
|
||||
"F4",
|
||||
"F5",
|
||||
"F6",
|
||||
"F7",
|
||||
"F8",
|
||||
"F9",
|
||||
"A2",
|
||||
"A3",
|
||||
"A4",
|
||||
"A5",
|
||||
"A6",
|
||||
"A7",
|
||||
"A8",
|
||||
"A9",
|
||||
],
|
||||
pure_getters: true,
|
||||
keep_fargs: false,
|
||||
unsafe_comps: true,
|
||||
unsafe: true,
|
||||
},
|
||||
mangle: true,
|
||||
});
|
||||
const code = minifiedElm.code;
|
||||
if (code) {
|
||||
return code;
|
||||
} else {
|
||||
throw "Error running terser.";
|
||||
}
|
||||
}
|
||||
|
||||
async function copyAssets() {
|
||||
|
30929
package-lock.json
generated
30929
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -49,6 +49,7 @@
|
||||
"sharp": "^0.25.2",
|
||||
"style-loader": "^1.0.0",
|
||||
"temp": "^0.9.0",
|
||||
"terser": "^5.3.7",
|
||||
"terser-webpack-plugin": "^2.3.5",
|
||||
"webpack": "4.42.1",
|
||||
"webpack-dev-middleware": "^3.7.0",
|
||||
@ -67,7 +68,6 @@
|
||||
"elm-review": "^2.3.3",
|
||||
"elm-test": "^0.19.1-revision2",
|
||||
"jest": "^26.0.1",
|
||||
"terser": "^5.3.7",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"files": [
|
||||
|
Loading…
Reference in New Issue
Block a user