【发布时间】:2018-08-08 18:12:35
【问题描述】:
我正在使用 webpack 和 gulp,这是我的 webpack 配置:
webpack.config.js
const path = require('path');
var HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
module.exports = {
output: {
publicPath: "./dist/",
path: path.join(__dirname, "/js/"),
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ["env"]
}
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
resolve: {
alias: {
moment: 'moment/src/moment'
}
},
externals: {
jquery: 'jQuery',
$: 'jQuery',
moment: 'moment',
"velocity-animate": 'velocity'
},
plugins: [
new HardSourceWebpackPlugin()
]
};
scripts.js(这就是这个文件中的全部内容)
import velocity from 'velocity-animate';
我得到这个错误
Uncaught ReferenceError: velocity is not defined
此行出错:
module.exports = velocity;
我的外部配置有问题吗? 这适用于 moment.js 和 jQuery,但不适用于velocity...
我试过了
"velocity-animate": 'velocity'
和
"velocity-animate": 'velocity-animate'
和
"velocity-animate": '"velocity-animate"'
这些都不起作用。如果第一个不是“velocity-animate”(包的名称),那么 Velocity.js 无论如何都会包含在脚本中。关于这个的文档并没有真正解释如何正确配置这个
真的有可能这个用例是如此的小众以至于地球上没有人可以解释它吗?
谢谢!
【问题讨论】:
-
什么时候出现错误?在编译还是运行时?
-
运行时。编译顺利
-
因为你将它定义为外部的,webpack 不会将它与你的应用程序捆绑在一起。您必须手动将其添加到您的 html 中。请确保它在您的 html 中可用
-
它可用,这不是问题。我什至没有在任何地方给 Velocity 打电话。
标签: javascript webpack velocity.js