A Vite plugin that detects the "use javascript" pragma and does absolutely nothing with it.
Because sometimes you need to explicitly tell your code to use JavaScript. Just like "use strict", but for JavaScript itself. Revolutionary.
npm install vite-plugin-use-javascript
# or
pnpm add vite-plugin-use-javascript
# or
yarn add vite-plugin-use-javascriptAdd 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;
}Nothing. Absolutely nothing. It detects the pragma and then... does nothing.
That's the entire point.
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.
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 devWhen 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.
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";
MIT