I'm setting up my dev environment under Ubuntu 20.04, with the following tools:
- PhpStorm 2020.3 as IDE
- CodeIgniter v4
- Vue 3.x
- Tailwind CSS+UI
I created a test project and following the docs I did:
npm install tailwindcss@latest
npm install @headlessui/vue @heroicons/vue
npm install vue@next
and the other stuff to create the skeleton of CodeIgniter project. Then I wrote a simple "Hello World" Vue application:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="output.css" type="text/css" rel="stylesheet" />
<script src="https://unpkg.com/vue@next"></script>
<script type="module" src="test1.js"></script>
</head>
<body>
<div id="hello-vue" class="demo">
{{ message }}
</div>
</body>
</html>
JS
const HelloVueApp = {
data() {
return {
message: 'Hello Vue!!'
}
}
}
Vue.createApp(HelloVueApp).mount('#hello-vue')
It works!
But as far as I understand this makes no sense: I used Vue.js from a CDN while I installed it locally using npm.
If I remove the <script src="https://unpkg.com/vue@next"></script> line I need to import Vue before I can use it.
It is contained under the node_modules folder.
So I tried:
import Vue from "/node_modules/vue/dist/vue.cjs.js"
and also:
import Vue from "../node_modules/vue/dist/vue.cjs.js"
But in both cases it does not find the file (error 404). What is the correct syntax?
Of course the file exists, if I type this from the project's root folder:
$ ls node_modules/vue/dist/vue.cjs.js
node_modules/vue/dist/vue.cjs.js