首页 > 解决方案 > JavaScript 和警报弹出没有在 wordpress 中运行,即使 gulpfile.js 运行

问题描述

在functions.php中我有以下代码

 function university_files()
{
  wp_enqueue_script('main-university-js', get_theme_file_uri('/js/scripts-bundled.js'), array('jquery'), '1.0', true);
}

add_action('wp_enqueue_scripts', 'university_files');

**and  in scripts.js i have code like this**

// 3rd party packages from NPM
import $ from 'jquery';
import slick from 'slick-carousel';

// Our modules / classes
import Search from './modules/Search';
import MyNotes from './modules/MyNotes';

// Instantiate a new object using our modules/classes
var search = new Search();
var mynotes = new MyNotes();

alert("this   is a js script");

**but whenever i try to reload page alert msg wont come**

**i have installed package json and the following is the gulpfile.js**

var gulp = require('gulp');

// Watch for file updates
gulp.task('watch', function () {
  gulp.watch('js/**/*.js').on('change', function (file) {
    //console.log(file);
    console.log(('JS changed' + ' (' + file.path + ')'));
  });
});

文件结构和 gulp watch 运行镜像

在此处输入图像描述

但是当我尝试运行 gulp 时,它会正确执行,但是在刷新 wordpress 主页后,我不会收到写在 scripts.js 文件中的警报消息(它在 js 文件夹下以及 bundledscripts.js 下)

在此处输入图像描述

标签: javascriptwordpressalert

解决方案


推荐阅读