Skip to content

Commit

Permalink
Merge pull request #120 from uphy/feature/esbuild
Browse files Browse the repository at this point in the history
Introduce esbuild instead of rollup
  • Loading branch information
uphy authored Nov 5, 2022
2 parents 76c2310 + b2397fd commit b95452d
Show file tree
Hide file tree
Showing 8 changed files with 3,316 additions and 506 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main.js
51 changes: 51 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
env: {
es6: true,
node: true,
browser: true,
},
extends: [
'plugin:prettier/recommended',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:import/typescript',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
modules: true,
},
},
plugins: ['@typescript-eslint', 'import'],
rules: {
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single', { avoidEscape: true }],
'@typescript-eslint/no-unused-vars': 0, // Configured in tsconfig instead.
'no-unused-vars': 0, // Configured in tsconfig instead.
'prettier/prettier': [
'error',
{
trailingComma: 'all',
printWidth: 120,
tabWidth: 2,
useTabs: false,
singleQuote: true,
bracketSpacing: true,
},
],
semi: ['error', 'always'],
'import/order': 'error',
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules
# build
main.js
*.js.map
styles.css

# obsidian
data.json
Expand Down
65 changes: 65 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import esbuildSvelte from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
import fs from 'fs';

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === 'production');

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins],
format: 'cjs',
watch: !prod,
target: 'es2016',
logLevel: "info",
// minify: prod ? true : false,
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
plugins: [
esbuildSvelte({
preprocess: sveltePreprocess(),
}),
{
name: "rename-styles",
setup(build) {
build.onEnd(() => {
const { outfile } = build.initialOptions;
const outcss = outfile.replace(/\.js$/, ".css");
const fixcss = outfile.replace(/main\.js$/, "styles.css");
if (fs.existsSync(outcss)) {
console.log("Renaming", outcss, "to", fixcss);
fs.renameSync(outcss, fixcss);
}
});
}
}
]
}).catch(() => process.exit(1));
Loading

0 comments on commit b95452d

Please sign in to comment.