I am developing a scheduling software for Windows 10, using Vue CLI 3.
The app needs to use "fs" module, but .. I could not find the way. There is no webpack config file anywhere. How can I solve the problem?
Vue CLI 3 is so different that I cannot use all the ways introduced at stackoverflow.
Please, help me.
To configure the Vue CLI server, we need to create a vue.config.js file in the root of the frontend project right beside package.json, containing: // options... Inside the module.export you can add configurations for your development server using devServer object.
No, not yet. I tried creating a new Vue project through the CLI 3 and hot reloading works there. I'm trying to figure out the differences. I faced the same issue (the console showed an error that said " [WDS] Disconnected") and here's what I did. Note that I was using the Vue UI tool for managing my project and I did not edit any config files.
Last night when I was messing around with my Apache configurations I found out that this error could be handled simply by Vue config file provided by Vue CLI 3. If you are struggling with the same problem, you are reading the right article. To understand the problem and the solution better let's talk a little bit about the error.
Error with sass and Vue 3 - Cannot find module 'sass' 3 Unable to use swiper/vue dependencies not found 2 node-gyp build error while running npm install in reactjs
You can use fs
when bootstrapping the application. For instance you could read a file in your file system to grab something, then add it to the application to use it somehow. If this is what you want (I doubt), you can just setup something like the following in your vue.config.js
:
const fs = require('fs');
const someFileContents = fs.readFileSync('my-path-to-the-file');
module.exports = {
lintOnSave: true,
configureWebpack: config => {
return {
plugins: [
new webpack.DefinePlugin({
'somevar': someFileContents,
})
]
}
},
}
And now, whenever you write somevar
in your web app code, webpack will had it replaced -at compile time- with the contents of the file. This may have some uses I think, but never did it.
Due to security reasons, you cannot use the fs
module in the browser: you won't be able to setup a Vue component that lists filesystem items or write to disk. It is not a webpack, node nor Vue issue, it is due to security limitations of browsers. The native fs
module of node.js talks to OS low level API's, and the browser can't access them.
should javascript be able to modify or read filesystems, a lot of devastating pretty bad security screw ups will arise.
Now, there is this pretty new browser API, the FileSystem API.
It does not allow to access user filesystem, yet it somehow simulates a sandboxed folder where your web application can store files. It may be useful for you depending on your use case, but does not have the greatest browser support.
There is no webpack config file anywhere.
In fact, all your webpack stuff in a vue-cli 3 app should be done via the vue.config.js
file: https://cli.vuejs.org/guide/webpack.html.
There you can execute arbitrary node.js code (in fact you can call fs
from there, as said before, since it is code running on your machine, not in the browser).
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