Skip to content

Commit

Permalink
chore: use tsc instead of rollup for dist types
Browse files Browse the repository at this point in the history
  • Loading branch information
HeartSquared committed Apr 8, 2024
1 parent 95450c7 commit 664e530
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 97 deletions.
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
"test:ci": "pnpm test -- --ci",
"test:treeshake": "agadoo ./dist/esm/index.mjs",
"clean": "rimraf dist",
"build:components": "rollup -c",
"build:components": "rollup -c && pnpm build:types",
"build:styles": "postcss styles/global.css --output dist/global.css",
"build:types": "tsc --project tsconfig.types.json",
"compile": "tsc",
"dist:clean": "rm ./dist/global.css ./dist/raw-styles.css",
"dist:combine-styles": "concat-cli -f ./dist/*.css -o ./dist/raw-styles.css",
Expand Down
97 changes: 1 addition & 96 deletions packages/components/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ import commonjs from "@rollup/plugin-commonjs"
// import jsonPlugin from "@rollup/plugin-json"
// import resolve from "@rollup/plugin-node-resolve"
import typescript from "@rollup/plugin-typescript"
// import dts from "rollup-plugin-dts"
import ignore from "rollup-plugin-ignore"
import nodeExternals from "rollup-plugin-node-externals"
import postcss from "rollup-plugin-postcss"

// ts-patch needs to be in CJS, but rollup uses EMS
// https://github.com/nonara/ts-patch/issues/106
// const require = createRequire(import.meta.url);
// const tspCompiler = require("ts-patch/compiler");

// const OUTPUT_DIR = "dist"

const sharedConfig = {
input: { index: "./src/index.ts", future: "./src/__future__/index.ts" },
// input: { index: "./src/index.ts" },
plugins: [
nodeExternals({
devDeps: true
Expand Down Expand Up @@ -53,10 +44,7 @@ const cjsConfig = {
plugins: [
...sharedConfig.plugins,
typescript({ tsconfig: "./tsconfig.cjs.json" }),
commonjs({
// requireReturnsDefault: "auto",
// defaultIsModuleExports: false
}),
commonjs(),
],
output: {
dir: "dist/cjs",
Expand All @@ -81,90 +69,7 @@ const esmConfig = {
}
}

const typesConfig = {
input: { index: "./src/index.ts" },
plugins: [
...sharedConfig.plugins,
typescript({ tsconfig: "./tsconfig.types.json" })
],
output: {
dir: "dist",
// format: "esm",
// preserveModules: true,
// entryFileNames: "[name].mjs",
}
}

// const getCompiledConfigByModuleType = format => ({
// input: { index: "./src/index.ts", future: "./src/__future__/index.ts" },
// plugins: [
// // nodeExternals({
// // devDeps: true
// // }),
// // Has to be the same as packages/components/tsconfig.json -> compilerOptions -> paths
// alias({
// entries: [
// { find: "~types", replacement: "src/types" },
// { find: "~utils", replacement: "src/utils" },
// { find: "~components", replacement: "src" },
// // i18n-react-intl package attempts to import locales from this path.
// // When rollup attempts to import from the 'find' path, it will be
// // redirected to import from the replacement path (same as storybook webpack config).
// {
// find: "__@cultureamp/i18n-react-intl/locales",
// replacement: "locales",
// },
// ],
// }),
// // resolve({
// // preferBuiltins: true,
// // extensions: [".js", ".jsx", ".ts", ".tsx"],
// // }),
// // postcss({
// // extract: true,
// // extensions: [".scss", ".css"],
// // }),
// // typescript({
// // tsconfig: `./tsconfig.${format}.json`,
// // typescript: tspCompiler,
// // }),
// // commonjs(),
// // image(),
// // jsonPlugin(),
// // // These libraries aren't used in KAIO, and require polyfills to be set up
// // // in consuming repos. Ignoring them here removes the need for extra setup in
// // // consuming repos.
// ignore(["stream", "http", "https", "zlib"]),
// // babel({ babelHelpers: "bundled" }),
// // getBabelOutputPlugin({
// // plugins: [
// // "@babel/plugin-transform-react-pure-annotations",
// // "babel-plugin-pure-static-props"
// // ]
// // }),
// ],
// output: [
// {
// dir: `${OUTPUT_DIR}/${format}`,
// format,
// sourcemap: true,
// preserveModules: true,
// entryFileNames: format === "esm" ? "[name].mjs" : "[name].cjs",
// },
// ],
// })

export default [
cjsConfig,
esmConfig,
typesConfig
// getCompiledConfigByModuleType("cjs"),
// getCompiledConfigByModuleType("esm"),
// // This step doesn't matter if it's cjs or esm, the output will be the same (esm is faster)
// {
// input: `./${OUTPUT_DIR}/esm/dts/index.d.ts`,
// output: [{ file: `${OUTPUT_DIR}/index.d.ts`, format: "esm" }],
// external: [/\.scss$/],
// plugins: [dts()],
// },
]

0 comments on commit 664e530

Please sign in to comment.