我目前使用esbuild加载我的静态资产。我使用它与一个package.json文件来维护我的javascript插件。jQuery插件可以在我的app.js中使用,但在我的node_modules中没有。数据交换模块错误:“未定义jQuery”
webpack有一个ProvidePlugin模块来解决这个问题。我该怎么用esbuild来做这件事?
app.js
import jquery from "jquery";
window.jQuery = jquery;
window.$ = jquery;
$ = jquery;
import datepicker from "jquery-ui/ui/i18n/datepicker-nl-BE"
---->>>>> ReferenceError: jQuery is not defined at datepicker-nl-BE.js:13 <<<<<--------dev.exs
watchers: [
#esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
node: ["esbuild.js", "--watch", cd: Path.expand("../assets", __DIR__)],
node: ["sass-watch.js",
cd: Path.expand("../assets", __DIR__),
into: IO.stream(:stdio, :line),
stderr_to_stdout: true
]
]esbuild.js
const esbuild = require('esbuild')
const sassPlugin = require('esbuild-plugin-sass')
// Decide which mode to proceed with
let mode = 'build'
process.argv.slice(2).forEach((arg) => {
if (arg === '--watch') {
mode = 'watch'
} else if (arg === '--deploy') {
mode = 'deploy'
}
})
const loader =
{
'.png': 'file',
'.ttf': 'file'
}
// Define esbuild options + extras for watch and deploy
let opts = {
entryPoints: ['js/app.js'],
bundle: true,
logLevel: 'info',
target: 'es2016',
outdir: '../priv/static/assets',
loader,
plugins: [sassPlugin()]
}
if (mode === 'watch') {
opts = {
watch: true,
sourcemap: 'inline',
...opts
}
}
if (mode === 'deploy') {
opts = {
minify: true,
...opts
}
}
// Start esbuild with previously defined options
// Stop the watcher when STDIN gets closed (no zombies please!)
esbuild.build(opts).then((result) => {
if (mode === 'watch') {
process.stdin.pipe(process.stdout)
process.stdin.on('end', () => { result.stop() })
}
}).catch((error) => {
process.exit(1)
})发布于 2022-01-14 18:50:22
似乎是用jquery-ui-dist解决的。
https://stackoverflow.com/questions/70250317
复制相似问题