【发布时间】:2018-04-29 21:38:57
【问题描述】:
我正在制作一个小型 vuejs 库,只是为了学习如何制作。我们称它为 swing,这就是文件的结构。
conf/、dist/、test/ 文件为空
我已经将此库推送到 github 并发布到 npm。 我使用
将它安装到我的应用程序中npm install --save vuejs-swing
我可以看到它已安装在 package.json 和 node_modules 文件夹中,但是当我这样做时:
import swing from 'vuejs-swing'
我收到此错误:
ERROR Failed to compile with 1 errors 11:42:41 AM
This dependency was not found:
* vuejs-swing in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/c
omponents/HelloWorld.vue
To install it, you can run: npm install --save vuejs-swing
显然是安装的,所以一定是配置问题
这是我的 webpack.config.js
var path = require('path')
var webpack = require('webpack')
module.exports = {
module: {
rules: [
// use babel-loader for js files
{ test: /\.js$/, use: 'babel-loader' },
// use vue-loader for .vue files
{ test: /\.vue$/, use: 'vue-loader' }
]
},
// default for pretty much every project
context: __dirname,
// specify your entry/main file
entry: {
app: './src/swing.js',
},
output: {
// specify your output directory...
path: path.resolve(__dirname, 'output'),
// and filename
filename: 'index.min.js'
},
resolve: {
// this is optional, but it lets you import .vue files without the .vue extension.
extensions: ['.js', '.json', '.vue']
}
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
编辑:
我会将赏金奖励给能够提供在 npm 中发布包所需的工具、配置并能够导入/使用它的人。
【问题讨论】:
-
你能给我们看一下swing.vue的代码吗?我想知道您是否没有正确导出组件
-
@TimHutchison 我只是在导出一个简单的东西,比如
export.module = 'swing'
标签: webpack ecmascript-6 vuejs2 vue-component node-modules