Skip to content

Commit

Permalink
Merge pull request #64 from kucrut/make-v4wp-options-optional
Browse files Browse the repository at this point in the history
Make v4wp options optional
  • Loading branch information
kucrut authored Oct 16, 2023
2 parents 2d49790 + ad81a04 commit e8ac527
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-grapes-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kucrut/vite-for-wp': patch
---

Make v4wp options optional
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ Create `vite.config.js`:
import { v4wp } from '@kucrut/vite-for-wp';

export default {
plugins: [ v4wp( { input: 'js/src/main.ts', outDir: 'js/dist' } ) ],
plugins: [
v4wp( {
input: 'js/src/main.ts', // Optional, defaults to 'src/main.js'.
outDir: 'js/dist', // Optional, defaults to 'dist'.
} ),
],
};
```

Expand All @@ -53,6 +58,8 @@ export default {
};
```

Refer to Rollup documentation on how to set entrypoints: https://rollupjs.org/configuration-options/#input

Feel free to [customise the configuration](https://vitejs.dev/config/) to add plugins, use https, etc:

```js
Expand Down
6 changes: 3 additions & 3 deletions src/exports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { dev_server } from './plugins/dev-server.js';
/**
* Vite for WP
*
* @type {(options: Options) => import('vite').PluginOption[]}
* @type {(options?: Options) => import('vite').PluginOption[]}
*/
export function v4wp( options = {} ) {
const { input = 'src/main.js', outDir } = options;
const { input, outDir } = options;

/** @type { import('vite').Plugin } */
const plugin = {
name: 'v4wp:config',
enforce: 'pre',

async config() {
config() {
return {
base: './',
build: {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"checkJs": true,
"declaration": true,
"esModuleInterop": true,
"module": "ES2022",
"moduleResolution": "Node",
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module '@kucrut/vite-for-wp' {
export function v4wp(options: Options): import('vite').PluginOption[];
export function v4wp(options?: Options): import('vite').PluginOption[];
export default function create_config(input: InputOption, out_dir: string, extra_config?: ExtraConfig): UserConfig;
export type ResolvedConfig = import('vite').ResolvedConfig;
export type UserConfig = import('vite').UserConfig;
Expand Down

0 comments on commit e8ac527

Please sign in to comment.