I have a file called myfile.js with functions that I want to reuse in multiple vue projects, specifically within the App.vue file.
Here is the file structure:
-- projec1
---- src
------ App.vue
-- project2
---- src
------ App.vue
-- myfile.js
Directly importing it like this does not work:
import * as alias from '../../myfile.js'
as the file path cannot be found during the production build resulting in an error message:
ERROR Failed to compile with 1 error3: 21: 38 PM
This relative module was not found: ../../myfile.js
Is there a simple solution to solve this issue? Perhaps something similar to defining a local dependency in package.json:
{
myLocalDependency: path/to/myFile.js
}
Then in App.vue we could import and use it like this:
<script>
import myLocalDependency from '...'
export default {
mounted: {
myLocalDependency.myPreciousFunction()
}
}
</script>