Skip to content

Commit

Permalink
Fix bugs on the build script
Browse files Browse the repository at this point in the history
  • Loading branch information
EverettSummer committed Nov 26, 2022
1 parent 5227b50 commit b118f15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 5 additions & 5 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
Expand All @@ -52,12 +52,12 @@
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
},
{
"replace": "src/index.html",
"with": "src/index.prod.html"
}
],
"index": {
"input": "src/index.prod.html",
"output": "index.html"
},
"outputHashing": "all"
},
"development": {
Expand Down
15 changes: 13 additions & 2 deletions scripts/process-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ const fs = require('fs');
const path = require('path');
const _ = require('lodash');

const envDict = process.env;
const DefaultEnv = {
SITE_TITLE: 'mira',
BASE_URL: '/',
CHROME_EXTENSION_ID: '',
FIREFOX_EXTENSION_ID: '',
FIREFOX_EXTENSION_URL: '',
EDGE_EXTENSION_ID: ''
};

const envDict = Object.assign({}, DefaultEnv, process.env);
console.log('enviroment variables:');
console.log(JSON.stringify(envDict, null, 2));
const envFileTemplatePath = path.join(__dirname, '../src/environments/_environment.prod.ts');
const envFilePath = path.join(__dirname, '../src/environments/environment.prod.ts');
const envFileTemplate = fs.readFileSync(envFileTemplatePath, {encoding: 'utf-8'});
console.log('Updating environment.prod.ts');
const compiledEnvFileTemplate = _.template(envFileTemplate);
fs.writeFileSync(envFilePath, compiledEnvFileTemplate(envDict), {encoding: 'utf-8'});

const indexTemplatePath = path.join(__dirname, 'src/_index.html');
const indexTemplatePath = path.join(__dirname, '../src/_index.html');
const indexTemplate = fs.readFileSync(indexTemplatePath, {encoding: 'utf-8'});
console.log('Updating index.html');
const compiledIndexTemplate = _.template(indexTemplate);
Expand Down
4 changes: 2 additions & 2 deletions src/environments/_environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const environment = {
production: false,
siteTitle: '<%= SITE_TILE =>',
production: true,
siteTitle: '<%= SITE_TITLE %>',
chromeExtensionId: '<%= CHROME_EXTENSION_ID %>',
firefoxExtensionId: '<%= FIREFOX_EXTENSION_ID %>',
firefoxExtensionUrl: '<%= FIREFOX_EXTENSION_URL %>',
Expand Down

0 comments on commit b118f15

Please sign in to comment.