jquery-ui 和 webpack,如何管理成模块? [英] jquery-ui and webpack, how to manage it into module?
问题描述
知道如何处理吗?我的意思是 jquery-ui 似乎不是 amd,我不知道如何管理它,知道吗?
any idea how to deal with that ? I mean jquery-ui seems not to be amd and I don't know how to manage that , any idea ?
推荐答案
你很幸运,我昨天就这样做了,很容易.
youre in luck I did this just that yesterday, it's rather easy.
npm install --save jquery jquery-ui
确保你有 jquery 别名以使用 webpack.config.js 中的插件解析
Make sure that you have jquery aliased to resolve with the plugin in the webpack.config.js
...
plugins: [
new webpack.ProvidePlugin({
"$":"jquery",
"jQuery":"jquery",
"window.jQuery":"jquery"
}),
...
然后在 webpack.config.js 中包含两个别名
Then include two aliases in the webpack.config.js
- node_modules 文件夹
- jquery-ui 文件夹
``````
resolve : {
alias: {
// bind version of jquery-ui
"jquery-ui": "jquery-ui/jquery-ui.js",
// bind to modules;
modules: path.join(__dirname, "node_modules"),
确保首先在您的应用启动文件中加载 jquery.
Make sure that jquery gets loaded first in your app startup file.
var $ = require("jquery"),
require("jquery-ui");
如果您需要使用主题,请配置 css-loader 和 file-loader.不要忘记 npm install 那些加载器.
If you need to use a theme configure the css-loader and the file-loader. Don't forget to npm install those loaders.
module: {
loaders: [
{ test: /.css$/, loader: "style!css" },
{ test: /.(jpe?g|png|gif)$/i, loader:"file" },
并在您的应用启动文件中使用.
And use in your app startup file.
require("modules/jquery-ui/themes/black-tie/jquery-ui.css");
require("modules/jquery-ui/themes/black-tie/jquery-ui.theme.css");
这篇关于jquery-ui 和 webpack,如何管理成模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!