将 owl carousel 包含到 npm project.All 方式
Include owl carousel to npm project.All way's
很久想用owl-carousel但是怎么也连接不上npm
webpack
.
官方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';
尝试麻木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"
})
很久想用owl-carousel但是怎么也连接不上npm
webpack
.
官方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';
尝试麻木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"
})