jquery-validation / jquery-validation

jQuery Validation Plugin library sources
https://jqueryvalidation.org/
MIT License
10.35k stars 2.79k forks source link

Need use it in vite #2495

Closed chan15 closed 3 months ago

chan15 commented 4 months ago

New feature motivation

I want to use this plugin on vite.

New feature description

vite is a popular js and css pack tool, use es module to compiler, hope this wonderful plugin can support it.

bytestream commented 3 months ago

You can import using import validate from 'jquery-validation'

chan15 commented 3 months ago

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import inject from "@rollup/plugin-inject";

export default defineConfig({
    plugins: [
        inject({
            $: 'jquery',
            jQuery: 'jquery',
        }),
        laravel({
            input: [
                'resources/css/app.scss',
                'resources/js/app.js',
            ],
            refresh: true,
        }),
    ],
});

app.js

import "jquery-validation";

$(function() {
    $('#frm').validate();
});

This is how I used the plugin, but I got ReferenceError: require is not defined