Skip to content

Commit

Permalink
feat: add support for ESM (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
taishinaritomi committed Aug 27, 2023
1 parent 10b44d8 commit 7e18937
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 46 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-queens-develop.md
@@ -0,0 +1,6 @@
---
"@excss/compiler": patch
"excss": patch
---

feat: add support for ESM
2 changes: 2 additions & 0 deletions .eslintrc.json
Expand Up @@ -60,6 +60,8 @@
"files": [
"./**/vite.config.ts",
"./**/vitest.config.ts",
"./**/next.config.mjs",
"./**/webpack.config.mjs",
"./packages/excss/src/compiler.ts",
"./packages/excss/src/plugins/webpack/{virtualLoader,loader}.ts",
"./playground/next/src/app/**/{page,layout,loading,error,template,head}.tsx",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/tests/compiler.spec.ts
@@ -1,6 +1,6 @@
import { format } from "prettier";
import { describe, it, expect } from "vitest";
import { transform } from "../binding/wasm-node/excss_compiler";
import { transform } from "../binding/wasm-node/excss_compiler.js";

describe("transform", () => {
it("basic", async () => {
Expand Down
22 changes: 1 addition & 21 deletions packages/excss/scripts/build.ts
@@ -1,6 +1,4 @@
import childProcess from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import * as esBuild from "esbuild";

function cmd(command: string) {
Expand Down Expand Up @@ -59,27 +57,9 @@ async function js() {
await Promise.all(buildQueue);
}

async function dts() {
const typesOutDir = path.join("dist/_types");
fs.mkdirSync(typesOutDir, { recursive: true });
fs.writeFileSync(
path.join(typesOutDir, "package.json"),
JSON.stringify({ type: "commonjs" }),
);

await cmd(
[
"tsc",
"--declaration --emitDeclarationOnly",
`--outDir ${typesOutDir}`,
"-p tsconfig.build.json",
].join(" "),
);
}

async function main() {
await js();
await dts();
await cmd("tsc -p tsconfig.build.json");
}

await main();
4 changes: 2 additions & 2 deletions packages/excss/src/ex.spec.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, expectTypeOf } from "vitest";
import type { Ex } from "./ex";
import { ex } from "./ex";
import type { Ex } from "./ex.ts";
import { ex } from "./ex.ts";

describe("ex", () => {
it("basic", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/excss/src/ex.ts
Expand Up @@ -3,7 +3,7 @@ import type {
ToLiteral,
Required as _Required,
Optional as _Optional,
} from "./utils/types";
} from "./utils/types.ts";

export { ex };
export type { Ex };
Expand Down
8 changes: 4 additions & 4 deletions packages/excss/src/index.ts
@@ -1,4 +1,4 @@
export { css } from "./css";
export { FILE_ID } from "./FILE_ID";
export { ex } from "./ex";
export type { Ex } from "./ex";
export { css } from "./css.ts";
export { FILE_ID } from "./FILE_ID.ts";
export { ex } from "./ex.ts";
export type { Ex } from "./ex.ts";
10 changes: 5 additions & 5 deletions packages/excss/src/plugins/next.ts
@@ -1,11 +1,11 @@
import type { Variants } from "@excss/compiler";
import type { NextConfig } from "next";
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
import type { ConfigurationContext } from "next/dist/build/webpack/config/utils";
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css/index.js";
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders/index.js";
import type { ConfigurationContext } from "next/dist/build/webpack/config/utils.js";
import type { Configuration, RuleSetRule } from "webpack";
import type { ExcssOption } from "./webpack/plugin";
import { ExcssPlugin } from "./webpack/plugin";
import type { ExcssOption } from "./webpack/plugin.ts";
import { ExcssPlugin } from "./webpack/plugin.ts";

type ExcssConfig = {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/excss/src/plugins/webpack/plugin.ts
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import type { Compiler } from "webpack";
import type { ExcssLoaderOption } from "./loader";
import type { ExcssLoaderOption } from "./loader.ts";

export type ExcssOption = Omit<
ExcssLoaderOption,
Expand Down
6 changes: 6 additions & 0 deletions packages/excss/tsconfig.build.json
@@ -1,4 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/_types",
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true
},
"exclude": ["src/__fixture__/**", "src/**/*.spec.*"]
}
@@ -1,5 +1,5 @@
const createBundleAnalyzer = require("@next/bundle-analyzer");
const { createExcss } = require("excss/next");
import createBundleAnalyzer from "@next/bundle-analyzer";
import { createExcss } from "excss/next";

const withBundleAnalyzer = createBundleAnalyzer({
enabled: process.env["ANALYZE"] === "true",
Expand All @@ -18,4 +18,4 @@ const nextConfig = {
swcMinify: true,
};

module.exports = withBundleAnalyzer(withExcss(nextConfig));
export default withBundleAnalyzer(withExcss(nextConfig));
2 changes: 1 addition & 1 deletion playground/next/tsconfig.json
@@ -1,12 +1,12 @@
{
"extends": "../../types/tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "bundler",
"baseUrl": ".",
"target": "ES2018",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"jsx": "preserve",
"moduleResolution": "node",
"noEmit": true,
"isolatedModules": true,
"resolveJsonModule": true,
Expand Down
1 change: 1 addition & 0 deletions playground/react-vite/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../types/tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "bundler",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"esModuleInterop": false,
"useDefineForClassFields": true,
Expand Down
3 changes: 2 additions & 1 deletion playground/react-webpack/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../types/tsconfig.base.json",
"compilerOptions": {
"jsx": "preserve"
"moduleResolution": "bundler",
"noEmit": true
}
}
@@ -1,9 +1,13 @@
const path = require("node:path");
const { ExcssPlugin } = require("excss/webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
import path from "node:path";
import { fileURLToPath } from "node:url";
import { ExcssPlugin } from "excss/webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";

module.exports = {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
mode: "production",
entry: path.join(__dirname, "./src/index.tsx"),
resolve: {
Expand Down
1 change: 1 addition & 0 deletions playground/solid-vite/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../types/tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "bundler",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"esModuleInterop": false,
"useDefineForClassFields": true,
Expand Down
4 changes: 3 additions & 1 deletion types/tsconfig.base.json
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"moduleResolution": "nodenext",
"allowImportingTsExtensions": true,
"jsx": "preserve",
"checkJs": false
}
Expand Down

0 comments on commit 7e18937

Please sign in to comment.