【发布时间】:2016-01-30 07:55:14
【问题描述】:
我尝试使用 react 和 webpack 来实现 wow.js。
我通过 npm 安装它。
npm install --save wow.js
安装完美。现在的问题是如何正确导入它。我无法让它继续工作,变得不确定。
我尝试了几种方法:
第一:
import wow from 'wow.js';
但是 webpack 无法编译。它说找不到模块。即使我使用完整的网址import wow from /node_modules/wow.js
第二:
我正在使用来自here的这个解决方案:
require('imports?this=>window!js/wow.js');
但我仍然找不到模块(我将路径更改为我的 node_modules)。
第三:
来自here:
我正在使用暴露模块并尝试new WOW().init(); 它显示Wow is undefined。
我没有使用他的第一个解决方案,因为我希望我的 html 看起来很简单,只有 bundle.js 脚本。
我找不到任何其他解决方案。我应该怎么做才能让它工作?
谢谢!
我的 webpack.config.js:
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'bootstrap-loader',
'webpack/hot/only-dev-server',
'./src/js/index.js'
],
output: {
path: __dirname + "/build",
publicPath: "/build/",
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
module: {
loaders: [
{
exclude: /node_modules/,
loader: 'react-hot!babel'
},
{
test: /\.css$/,
loader: 'style!css!postcss'
},
{
test: /\.scss$/,
loader: 'style!css!postcss!sass'
},
{ test: /\.(woff2?|ttf|eot|svg|otf)$/, loader: 'url?limit=10000' },
{
test: 'path/to/your/module/wow.min.js',
loader: "expose?WOW"
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
},
postcss: [autoprefixer]
};
【问题讨论】:
-
我认为您正在安装 wow.js,而它只是 wowjs 符合他们的 github 页面。 github.com/matthieua/WOW
标签: javascript reactjs webpack