generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from uphy/feature/esbuild
Introduce esbuild instead of rollup
- Loading branch information
Showing
8 changed files
with
3,316 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ node_modules | |
# build | ||
main.js | ||
*.js.map | ||
styles.css | ||
|
||
# obsidian | ||
data.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Oops, something went wrong.