gpt4 book ai didi

javascript - 将 owl carousel 包含到 npm 项目中。All ways

转载 作者:行者123 更新时间:2023-11-30 20:23:34 24 4
gpt4 key购买 nike

很长一段时间想使用owl-carousel但是无法通过npmwebpack以任何方式连接它。

官方site of npm

Add jQuery via the "webpack.ProvidePlugin" to your webpack configuration:

const webpack = require('webpack');

//...
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
],
//...

我的webpack配置文件中已经有了这个配置

Load the required stylesheet and JS:

import 'owl.carousel/dist/assets/owl.carousel.css';
import 'owl.carousel';

尝试 NumPy 1

在这样的配置中(只将 css 文件更改为 scss)我有以下错误

无法读取未定义的属性“fn”

尝试编号2

像这样也包含不起作用。

import 'imports?jQuery=jquery!owl.carousel';

我收到以下错误 Module not found: Error: Can't resolve 'imports' in 'D:\master\my path '

试试数字3

import owlCarousel from "owl.carousel";

第一次尝试时出错

我的webpack.config.js

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const webpack = require('webpack');

let conf = {
entry: {
index: "./src/index.js"
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: "[name]bundle.js",
publicPath: "dist/"
},
devServer: {
overlay:true
},
module: {
rules: [
{
test: /\.js/,
loader:"babel-loader",
},
{
test:/\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
options: {
url: false,
minimize: true,
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
})
}
]
},
plugins: [
new ExtractTextPlugin({
filename: "[name].css"
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: "build/index.html",
hash: true,
chunks: ["index"]
}),

new webpack.ProvidePlugin({
'$': "jquery",
'jQuery': "jquery",
'Popper': 'popper.js',
"Bootstrap": "bootstrap.js"
})
]
};

module.exports = (env, options) => {

let production = options.mode === "production";

conf.devtool = production ? false : "eval-sourcemap";

return conf;
}

在我的项目中,我有 2 个包

index.js

import $ from "jquery";
import jQuery from "jquery";

import "../styles/main/main.scss";
import "normalize.scss/normalize.scss";
import "bootstrap/dist/js/bootstrap.bundle.min.js";

//in here including owl-config where I config my owl carousel

import * as owlConfig from "./owl-config";

//after this more js code's

第二个 owl-config.js 我在这个文件中做的所有 trie

我的依赖项

"dependencies": {
"bootstrap": "^4.1.1",
"normalize.scss": "^0.1.0",
"owl.carousel": "^2.2.0",
"jquery": "^3.3.1",
"popper": "^1.0.1"
}

最佳答案

问题是我没有正确执行文档中写的内容

//...
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
],
//...

我的 webpack.config.js

里有什么
new webpack.ProvidePlugin({
'$': "jquery",
'jQuery': "jquery",
'Popper': 'popper.js',
"Bootstrap": "bootstrap.js"
})

我如何改变它和工作的

new webpack.ProvidePlugin({
'$': "jquery",
'jQuery': "jquery",
'window.jQuery': 'jquery',
'Popper': 'popper.js',
"Bootstrap": "bootstrap.js"
})

关于javascript - 将 owl carousel 包含到 npm 项目中。All ways,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51189018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com