我正在 Symfony 中用 encore 和 yarn 做一個腳本 JS,當我不使用 jquery 并且從不需要他時,我的 JS 工作正常。但是目前我添加了 jquery,const $ = require('jquery')例如我的腳本不起作用并且我沒有收到錯誤消息。我嘗試評論.enableSingleRuntimeChunk(),使用 CDN 添加 jquery,嘗試另一個項目。沒變化。//base.html.twig{% block javascripts %} <script src="{{ asset('build/runtime.js') }}"></script> <script src="{{ asset('build/app.js') }}" type="text/javascript"></script>{% endblock %}// Need jQuery? Install it with "yarn add jquery", then uncomment to require it.const $ = require('jquery');console.log('hello');Encore // directory where compiled assets will be stored .setOutputPath('public/build/') .copyFiles({ from: './assets/images' }) // public path used by the web server to access the output path .setPublicPath('/build') // only needed for CDN's or sub-directory deploy //.setManifestKeyPrefix('build/') /* * ENTRY CONFIG * * Add 1 entry for each "page" of your app * (including one that's included on every page - e.g. "app") * * Each entry will result in one JavaScript file (e.g. app.js) * and one CSS file (e.g. app.fontawesome) if your JavaScript imports CSS. */ .addEntry('app', './assets/js/app.js') .addEntry('main', './assets/js/main.js') //.addEntry('page2', './assets/js/page2.js') // When enabled, Webpack "splits" your files into smaller pieces for greater optimization. .splitEntryChunks() // will require an extra script tag for runtime.js // but, you probably want this, unless you're building a single-page app .enableSingleRuntimeChunk()
當我將 jquery 添加到我的網(wǎng)站時,我的 JS 不起作用
有只小跳蛙
2021-09-30 16:46:00