Answer the question
In order to leave comments, you need to log in
How to fix the error when trying to include a built vue component: "export 'default' was not found in?
Written a simple single-file component in Vue JS. The interest is to assemble it using Webpack into one js executable file, which can then be included using import in other vue components.
For example, here is our test.vue component:
<template>
<div @click="clickButton">TEST</div>
</template>
<script>
export default {
name: 'test',
methods: {
clickButton () {
console.log('на кнопку нажали')
}
}
}
</script>
"use strict"
var path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
entry: {
test: './src/components/test.vue'
},
output: {
path: path.resolve(__dirname, './lib/components'),
publicPath: '/lib/',
filename: '[name].js',
chunkFilename: '[id].js',
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
preserveWhitespace: false
}
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: 'env'
}
},
exclude: /node_modules/
},
]
},
plugins: [
new VueLoaderPlugin()
]
}
import test from 'path/test_project/lib/components/test.'
export default {
name: "my_page",
data () {
return {}
},
components: {
test
}
}
{
"presets": ,
"plugins": [
"transform-export-default"/*,
"add-module-exports" */
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question