Skip to content

Commit d5d26e8

Browse files
author
Antoine Greuzard
committed
Update build process & dependencies
Changes are made to streamline the build process and update project dependencies. Converted the project to use Vite for bundling the JavaScript files. New entry points are defined in the new 'vite.config.js' file. Front-end and back-end code now get their own bundles. 'form.js' now directly imports its dependencies - 'Sortable' and 'tinymce' - instead of relying on global variables. This ensures that the dependencies are version managed and can be updated easily. The '.gitignore' file is updated to exclude the 'dist/' folder as it contains generated code. The enqueuing scripts in 'functions.php' file are updated to load the new bundled files instead of individual files. This refactoring enhances the maintainability of the project by using modern development tools.
1 parent a757a5b commit d5d26e8

File tree

9 files changed

+89
-9
lines changed

9 files changed

+89
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
**/nbproject/Package-*.bash
1919
build/
2020
nbbuild/
21-
dist/
2221
nbdist/
2322
.nb-gradle/
2423

back-end/post-type/form/form.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* global Sortable, influactiveFormsTranslations, tinymce */
1+
import Sortable from 'sortablejs'
2+
import tinymce from 'tinymce/tinymce'
3+
4+
/* global influactiveFormsTranslations */
25

36
function recalculateFieldIndexes() {
47
const container = document.getElementById('influactive_form_fields_container')

dist/backEndForm.bundled.js

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/backEndLayout.bundled.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/backEndTab.bundled.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/frontEnd.bundled.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function influactive_form_edit( string $hook ): void {
4949
return;
5050
}
5151

52-
wp_enqueue_script( 'influactive-form', plugin_dir_url( __FILE__ ) . 'back-end/post-type/form/form.js', array(
53-
'influactive-form-sortable',
52+
wp_enqueue_script( 'influactive-form', plugin_dir_url( __FILE__ ) . 'dist/backEndForm.bundled.js', array(
5453
'wp-tinymce',
5554
'influactive-tabs',
5655
'influactive-form-layout'
@@ -76,14 +75,13 @@ function influactive_form_edit( string $hook ): void {
7675
'Number' => __( 'Number', 'influactive-forms' ),
7776
'Freetext' => __( 'Free text', 'influactive-forms' ),
7877
) );
79-
wp_enqueue_script( 'influactive-form-sortable', 'https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.0/Sortable.min.js', array(), '1.15.0', true );
8078
wp_enqueue_style( 'influactive-form', plugin_dir_url( __FILE__ ) . 'back-end/post-type/form/form.min.css', array(), '1.2.2' );
8179

82-
wp_enqueue_script( 'influactive-tabs', plugin_dir_url( __FILE__ ) . 'back-end/post-type/tab/tab.js', array(), '1.2.2', true );
80+
wp_enqueue_script( 'influactive-tabs', plugin_dir_url( __FILE__ ) . 'dist/backEndTab.bundled.js', array(), '1.2.2', true );
8381
wp_enqueue_style( 'influactive-tabs', plugin_dir_url( __FILE__ ) . 'back-end/post-type/tab/tab.min.css', array(), '1.2.2' );
8482

8583
wp_enqueue_style( 'influactive-form-layout', plugin_dir_url( __FILE__ ) . 'back-end/post-type/layout/layout.min.css', array(), '1.2.2' );
86-
wp_enqueue_script( 'influactive-form-layout', plugin_dir_url( __FILE__ ) . 'back-end/post-type/layout/layout.js', array(), '1.2.2', true );
84+
wp_enqueue_script( 'influactive-form-layout', plugin_dir_url( __FILE__ ) . 'dist/backEndLayout.bundled.js', array(), '1.2.2', true );
8785
wp_localize_script( 'influactive-form-layout', 'influactiveFormsTranslations', array(
8886
'delete_layout' => __( 'Delete layout', 'influactive-forms' ),
8987
) );
@@ -127,7 +125,7 @@ function influactive_form_shortcode_enqueue(): void {
127125
$script_handle = [];
128126
}
129127

130-
wp_enqueue_script( 'influactive-form', plugin_dir_url( __FILE__ ) . 'front-end/form.js', $script_handle, '1.2.2', true );
128+
wp_enqueue_script( 'influactive-form', plugin_dir_url( __FILE__ ) . 'dist/frontEnd.bundled.js', $script_handle, '1.2.2', true );
131129
wp_enqueue_style( 'influactive-form', plugin_dir_url( __FILE__ ) . 'front-end/form.min.css', [], '1.2.2' );
132130

133131
wp_localize_script( 'influactive-form', 'ajaxObject', [ 'ajaxurl' => admin_url( 'admin-ajax.php' ) ] );

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"description": "A plugin to create custom forms and display them anywhere on your website.",
55
"type": "module",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"dev": "vite",
8+
"build": "vite build",
9+
"serve": "vite preview",
10+
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
11+
"lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx .",
12+
"pre-commit": "npm run lint:fix",
13+
"pre-push": "npm run lint:fix"
814
},
915
"repository": {
1016
"type": "git",

vite.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from 'vite'
2+
3+
export default defineConfig({
4+
build: {
5+
rollupOptions: {
6+
input: {
7+
frontEnd: 'front-end/form.js',
8+
backEndForm: 'back-end/post-type/form/form.js',
9+
backEndLayout: 'back-end/post-type/layout/layout.js',
10+
backEndTab: 'back-end/post-type/tab/tab.js',
11+
},
12+
output: {
13+
entryFileNames: '[name].bundled.js',
14+
},
15+
},
16+
},
17+
})

0 commit comments

Comments
 (0)