Skip to content

Commit

Permalink
feat: add type module to package.json and fix esbuild issues
Browse files Browse the repository at this point in the history
had to add --experimental-modules flag while running node script
  • Loading branch information
oze4 committed Aug 6, 2021
1 parent 9a7eb07 commit e44ce4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
42 changes: 19 additions & 23 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const { build } = require('esbuild');
const { red, green, yellow, italic } = require('chalk');
const rimraf = require('rimraf');
const path = require('path');
const fs = require('fs');
import esbuild from 'esbuild';
import rimraf from 'rimraf';
import path from 'path';
import fs from 'fs';

const { log } = console;
const { stdout, stderr, exit } = process;
const { log, error } = console;

/**
* OUTPUT PATH IS SET HERE!!
Expand All @@ -14,17 +12,17 @@ const { stdout, stderr, exit } = process;
*
* !! NO TRAILING SLASH !!
*/
const BUILD_DIR = 'dist';
const BUILD_DIR = './dist';

stdout.write(yellow(`-Cleaning build artifacts from : '${BUILD_DIR}' `));
log(`-Cleaning build artifacts from : '${BUILD_DIR}' `);

rimraf(path.resolve(__dirname, BUILD_DIR), async (error) => {
if (error) {
stderr.write(red(`err cleaning '${BUILD_DIR}' : ${error.stderr}`));
exit(1);
rimraf(path.resolve(BUILD_DIR), async (err) => {
if (err) {
error(`err cleaning '${BUILD_DIR}' : ${error.stderr}`);
process.exit(1);
}

log(green.italic('successfully cleaned build artifacts'));
log('successfully cleaned build artifacts');

const options = {
entryPoints: getFilesRecursive('./src', '.js'),
Expand All @@ -39,20 +37,18 @@ rimraf(path.resolve(__dirname, BUILD_DIR), async (error) => {
}
};

log(yellow('-Begin bundling'));
log('-Begin building');

try {
await build(options);
await esbuild.build(options);
log(
green(`\nSuccessfully bundled to '${BUILD_DIR}'`),
yellow('\n[note]'),
italic.green(': this path is relative to the root of this project)')
`\nSuccessfully built to '${BUILD_DIR}''\n[note] : this path is relative to the root of this project)'`
);
} catch {
stderr.write(red(`\nerror bundling : ${error.stderr}`));
exit(1);
} catch (err) {
error(`\nERROR BUILDING : ${err}`);
process.exit(1);
} finally {
exit(0);
process.exit(0);
}
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@material-table/core",
"type": "module",
"publishConfig": {
"access": "public"
},
Expand All @@ -14,7 +15,7 @@
],
"scripts": {
"start": "./node_modules/.bin/webpack serve --config ./__tests__/demo/webpack.config.js --mode development --progress",
"build:esbuild": "node esbuild.config.js",
"build:esbuild": "node esbuild.config.js --experimental-modules",
"build": "npm run build:esbuild",
"lint": "npm run eslint && npm run tsc",
"eslint": "./node_modules/.bin/eslint src/** -c ./.eslintrc --ignore-path ./.eslintignore",
Expand Down

0 comments on commit e44ce4f

Please sign in to comment.