simple builder for M78 projects, which also contain several developer tools.
usage
First, add m78-build-tools
to your project, use your favorite package manager
auto inject config
generate config via cli,
npm init -y
npx m78-build-tools init
will create below files:
.eslintrc.cjs
.npmrc
.prettierrc.cjs
jest.config.js
m78-lib.config.js
tsconfig.json
tsconfig.lib.json
and modify these fields in package.json
scripts
devDependencies
files
main
type
typings
publishConfig
build
- Make sure
m78-lib.config.js
exist in project root. for config detail, see defineConfig.d.ts
import sass from "sass";
import { mkdir, writeFile } from "node:fs/promises";
import { defineConfig } from "@m78/build-tools/defineConfig.js";
// import { defineCommonConfig } from "@m78/build-tools/defineConfig.js"; // commonConfig if need
// export const commonConfig = defineCommonConfig({ ... })
export default defineConfig({
build: [
{
inpDir: "src",
outDir: "esm",
swcConfig: {
module: {
type: "es6",
},
},
},
],
});
2.run npx m78-build-tools build
pass --skip-declaration-emit to block the student declaration file
test
built-in test by jest
and @testing-library/react
.
- add
jest.config.js
to project root.
export { default } from "@m78/lib-build/jest.config.js";
-
write test code
-
run test
npx jest
example
start dev server, run your code.
suppose the root directory has the following code
examples
| - func1
|- index.html
|- xxx.tsx # use in index.html <script type="module" src="./index.tsx"></script>
| - func2
|- index.html
run the specified example
npx m78-build-tools example func1 # run func1
lint
provide eslint and prettier base config, usage by follow:
- add config
.eslintrc.cjs
module.exports = {
extends: [require.resolve("@m78/lib-build/.eslintrc.cjs")],
rules: {},
};
.prettierrc.cjs
const config = require("@m78/lib-build/.prettierrc.cjs");
module.exports = {
...config,
};