最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue SPA - How to hide .vue files when rendered in browser - Stack Overflow

programmeradmin1浏览0评论

I'm working on a Single Page App developed in Vue.js hosted on a node.js server.

At the moment it is still under development but eventually it will be exposed to external customers, and since we will deal with sensitive data we would like to avoid to have the .vue files and the relative file-tree structure visible when users inspect the element in devtool.

See attached screenshot as a sample that shows the files I would like to hide.

Is there a way to achieve that?

I'm working on a Single Page App developed in Vue.js hosted on a node.js server.

At the moment it is still under development but eventually it will be exposed to external customers, and since we will deal with sensitive data we would like to avoid to have the .vue files and the relative file-tree structure visible when users inspect the element in devtool.

See attached screenshot as a sample that shows the files I would like to hide.

Is there a way to achieve that?

Share Improve this question asked Nov 15, 2018 at 0:23 AdrianoAdriano 3,9345 gold badges35 silver badges55 bronze badges 3
  • 1 there is a topic already addressing the same subject. stackoverflow./questions/49096454/… – Hamilton Gabriel Commented Nov 15, 2018 at 1:50
  • Thanks, Hamilton, I'll have a look :) – Adriano Commented Nov 15, 2018 at 2:26
  • I hope it works. – Hamilton Gabriel Commented Nov 15, 2018 at 2:36
Add a ment  | 

3 Answers 3

Reset to default 8

I was able to make webpack export the SPA in a bundle by playing around with the config file.

In the file ./config/index.js I have changed the following flags:

build: {
    // other code...

    devtool: '',  // Previously it was set as '#source-map'
    productionSourceMap: false, // Previously it was set as true
    cssSourceMap: false, // Previously set as true

    // other code...
}

I've found the solution by reading the webpack documentation where it explains what the settings do: https://webpack.js/configuration/devtool/#production

Thanks everyone for putting me in the right direction.

It seems you are running on development mode of vue. And Of course files will be visible by then. When shipping a Vue SPA, it should be build and piled into chunks of JS.

You can build a production version of your spa by running.

npm run build

This will produce 1 folder and 1 file inside the dist

--dist
----static
----index.html

When this were served. No .vue files will be visible anymore. And when you check it on Browsers Dev tools. It should look more like of this

The folders node_modules, src, and theme should be a level up in the folder structure. Therefore, you have to modify your paths pointing to those files.

The app.js can be in that folder only with files that are JS executables.

发布评论

评论列表(0)

  1. 暂无评论