Skip to content

serhalp/vite-plugin-use-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-use-javascript

A Vite plugin that detects the "use javascript" pragma and does absolutely nothing with it.

Why?

Because sometimes you need to explicitly tell your code to use JavaScript. Just like "use strict", but for JavaScript itself. Revolutionary.

Installation

npm install vite-plugin-use-javascript
# or
pnpm add vite-plugin-use-javascript
# or
yarn add vite-plugin-use-javascript

Usage

Add the plugin to your vite.config.ts:

import { defineConfig } from 'vite';
import useJavaScript from 'vite-plugin-use-javascript';

export default defineConfig({
  plugins: [
    useJavaScript()
  ]
});

Now you can use the "use javascript" pragma in your files:

"use javascript";

function add(a, b) {
  return a + b;
}

Or even in function bodies:

function multiply(a, b) {
  "use javascript";
  return a * b;
}

What does it do?

Nothing. Absolutely nothing. It detects the pragma and then... does nothing.

That's the entire point.

Options

verbose

If you want to see when the plugin detects the pragma (but still does nothing with it), you can enable verbose mode:

import { defineConfig } from 'vite';
import useJavaScript from 'vite-plugin-use-javascript';

export default defineConfig({
  plugins: [
    useJavaScript({ verbose: true })
  ]
});

This will log a message when it finds "use javascript" and then proceed to do nothing about it.

Demo

Want to see the plugin in action (doing nothing)? The demo/ directory contains a minimal Vite app with files that use the "use javascript" pragma.

# Install dependencies
pnpm install

# Build the plugin
pnpm run build

# Run the demo dev server
cd demo
pnpm run dev

When Vite starts, check your terminal output. You'll see logs like:

[vite-plugin-use-javascript] Found "use javascript" pragma in /path/to/demo/src/main.ts
[vite-plugin-use-javascript] Doing absolutely nothing with it. ✨
[vite-plugin-use-javascript] Found "use javascript" pragma in /path/to/demo/src/example.js
[vite-plugin-use-javascript] Doing absolutely nothing with it. ✨

That's it. That's the plugin. It detects the pragma at build time and does nothing.

FAQ

Q: Does this actually do anything? A: No.

Q: Should I use this in production? A: Absolutely not. But also, yes. But really, no.

Q: What about "use typescript"? A: That's for the sequel.

Q: Is this a joke? A: "use javascript";

License

MIT

About

Vite plugin that detects the 'use javascript' directive and does absolutely nothing with it

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published