Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.7.x] Build MJS and CJS versions of the plugin #189

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ Update your NPM scripts in `package.json`:
}
```

You should also add `"type": "module"` as a top-level key / value pair to your project's `package.json` by running the following command:

```shell
npm pkg set type="module"
```

### Vite compatible imports

Vite only supports ES modules, so if you are upgrading an existing application you will need to replace any `require()` statements with `import`. You may refer to [this pull request](https://github.com/laravel/laravel/pull/5895/files) for an example.
Expand Down Expand Up @@ -265,7 +271,37 @@ Then you will need to specify the base URL for assets in your application's entr

### Optional: Configure Tailwind

If you are using Tailwind, perhaps with one of Laravel's starter kits, you will need to create a `postcss.config.js` file. Tailwind can generate this for you automatically:
If you are using Tailwind, perhaps with one of Laravel's starter kits, you will need migrate your `tailwind.config.js` to use [Vite compatible imports](#vite-compatible-imports) and exports.

```diff
- const defaultTheme = require('tailwindcss/defaultTheme');
+ import defaultTheme from 'tailwindcss/defaultTheme';
+ import forms from '@tailwindcss/forms';

/** @type {import('tailwindcss').Config} */
- module.exports = {
+ export default {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
'./resources/js/**/*.vue',
],

theme: {
extend: {
fontFamily: {
sans: ['Figtree', ...defaultTheme.fontFamily.sans],
},
},
},

- plugins: [require('@tailwindcss/forms')],
+ plugins: [forms],
};
```

You will also need to create a `postcss.config.cjs` file. Tailwind can generate this for you automatically:

```shell
npx tailwindcss init -p
Expand All @@ -274,7 +310,7 @@ npx tailwindcss init -p
Or, you can create it manually:

```js
module.exports = {
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
Expand Down
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@
},
"license": "MIT",
"author": "Laravel",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"./inertia-helpers": {
"import": "./inertia-helpers/index.js",
"types": "./inertia-helpers/index.d.ts"
}
},
"files": [
"/dist",
"/inertia-helpers"
],
"scripts": {
"build": "npm run build-plugin && npm run build-inertia-helpers",
"build-plugin": "rm -rf dist && tsc && cp src/dev-server-index.html dist/",
"build-plugin": "rm -rf dist && npm run build-plugin-types && npm run build-plugin-esm && npm run build-plugin-cjs && cp src/dev-server-index.html dist/",
"build-plugin-types": "tsc --emitDeclarationOnly",
"build-plugin-cjs": "esbuild src/index.ts --platform=node --format=cjs --outfile=dist/index.cjs",
jessarcher marked this conversation as resolved.
Show resolved Hide resolved
"build-plugin-esm": "esbuild src/index.ts --platform=node --format=esm --outfile=dist/index.mjs",
jessarcher marked this conversation as resolved.
Show resolved Hide resolved
"build-inertia-helpers": "rm -rf inertia-helpers && tsc --project tsconfig.inertia-helpers.json",
"lint": "eslint --ext .ts ./src ./tests",
"test": "vitest run"
Expand All @@ -31,6 +43,7 @@
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"esbuild": "0.16.10",
timacdonald marked this conversation as resolved.
Show resolved Hide resolved
"eslint": "^8.14.0",
"typescript": "^4.6.4",
"vite": "^4.0.0",
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.inertia-helpers.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "inertia-helpers",
"target": "ES2020",
"module": "ES2020",
"outDir": "inertia-helpers"
},
"include": [
"./src/inertia-helpers/index.ts"
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"outDir": "./dist",
"target": "ES2019",
"module": "commonjs",
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true,
Expand Down