Skip to content

Commit

Permalink
build: modernize build process
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Aug 5, 2021
1 parent 0e5a32f commit 34948c4
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelogrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
// ? See https://github.com/conventional-changelog/conventional-changelog

const debug = require('debug')(
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const debug = require('debug')(`${require('./package.json').name}:eslint-config`);
const restrictedGlobals = require('confusing-browser-globals');

Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
// * Every now and then, we adopt best practices from CRA
// * https://tinyurl.com/yakv4ggx

Expand Down
2 changes: 2 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions expect-env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* eslint-disable no-console */

const debug = require('debug')(`${require('./package.json').name}:expect-env`);
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
restoreMocks: true,
resetMocks: true,
Expand Down
2 changes: 2 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
'*.md': 'remark -o --use reference-links --use gfm --use frontmatter',
'package.json': 'sort-package-json',
Expand Down
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const withBundleAnalyzer = require('@next/bundle-analyzer');
const { verifyEnvironment } = require('./expect-env');

Expand Down
2 changes: 2 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = {
endOfLine: 'lf',
printWidth: 80,
Expand Down
2 changes: 2 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const debug = require('debug')(
`${require('./package.json').name}:semantic-release-config`
);
Expand Down
2 changes: 2 additions & 0 deletions spellcheck-commit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
/* eslint-disable no-console */

const spellcheck = require('spellchecker');
const pkg = require('./package.json');
const read = require('fs').promises.readFile;
Expand Down
20 changes: 15 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// This webpack config is used to transpile src to dist, compile externals,
// compile executables, etc

Expand All @@ -7,22 +9,30 @@ const { verifyEnvironment } = require('./expect-env');
const nodeExternals = require('webpack-node-externals');
const debug = require('debug')(`${require('./package.json').name}:webpack-config`);

let env = {};
let sanitizedEnv = {};
let { NODE_ENV, ...sanitizedProcessEnv } = { ...process.env, NODE_ENV: 'production' };

try {
require('fs').accessSync('.env');
env = require('dotenv').config().parsed;
debug('new env vars: %O', env);
({ NODE_ENV, ...sanitizedEnv } = require('dotenv').config().parsed);
debug(`NODE_ENV: ${NODE_ENV}`);
debug('sanitized env: %O', sanitizedEnv);
} catch (e) {
debug(`env support disabled; reason: ${e}`);
}

verifyEnvironment();

const envPlugins = [
// ? NODE_ENV is not a "default" (unlike below) but an explicit overwrite
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}),
// ? Load our .env results as the defaults (overridden by process.env)
new EnvironmentPlugin({ ...env, ...process.env }),
// ? Create shim process.env for undefined vars (per my tastes!)
new EnvironmentPlugin({ ...sanitizedEnv, ...sanitizedProcessEnv }),
// ? Create shim process.env for undefined vars
// ! The above already replaces all process.env.X occurrences in the code
// ! first, so plugin order is important here
new DefinePlugin({ 'process.env': '{}' })
];

Expand Down

0 comments on commit 34948c4

Please sign in to comment.