I'm new in Vue. I just create vue project by vue create my-project-name
.
works fine.
But how can I change the folder structure? wrap src
and public
in client
folder?
app folders:
|-client
|- src
|- public
|- package.json
and still use all the cli features?
vue. config. js is an optional config file that will be automatically loaded by @vue/cli-service if it's present in your project root (next to package. json ). You can also use the vue field in package.
Change Default Port via Terminal In Vue CLI 3.0, we can change the port just by adding the port number after the --port option. We have to append --port with the port number after npm run serve command. The first -- is used to pass the port option to the npm script and not to the npm itself.
A Vue application consists of a root Vue instance created with new Vue or createApp function(s), optionally organized into a tree of nested, reusable components. Creating a new Vue instance generally means an instruction for the Vue application to render a component, generally, it is the App component.
src/views is typically used for your main pages in the application that you navigate via router. src/components is used for the reusable components that you use inside your main pages (multiple times inside the same page or across different pages)
Change serve
and build
scripts in package.json
:
vue-cli-service serve
to vue-cli-service serve client/src
vue-cli-service build
to vue-cli-service build client/src
And devServer.contentBase
in vue.config.js
const path = require('path');
module.exports = {
devServer: {
contentBase: path.join(__dirname, 'client/public')
}
}
Recently stumbled on this issue and found a workaround. Ruslan's method did not work for me, unfortunately.
This is my basic full-stack folder structure.
In order to get it to work, I added the following to vue.config.js
const path = require('path')
module.exports = {
pages: {
index: {
entry: 'client/src/main.js',
template: 'client/public/index.html'
}
},
configureWebpack: {
resolve: {
alias: {
'@': path.resolve(__dirname, 'client/src')
}
}
},
chainWebpack: config => {
config
.plugin('copy')
.use(require('copy-webpack-plugin'), [[{
from: path.resolve(__dirname, 'client/public'),
to: path.resolve(__dirname, 'dist'),
toType: 'dir',
ignore: ['.DS_Store']
}]])
}
}
This should
@
alias functionality.public
folder to the dist
folder.Resources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With