When vue package, the difference between the processing assets directory and files under static (nodeModule plugin source after modification, the file should be placed in the package directory static)

To answer this question, we first need to understand how to deal with Webpack static assets. In the  *.vue assembly, all templates and CSS will be  vue-html-loader and  css-loader resolve, and find resources URL. For example,  <img src="./logo.png">
and  background: url(./logo.png) in "./logo.png" resource opposite path, by Webpack module dependency is resolved .

Because  logo.png not JavaScript, when the module is considered dependent, use  url-loader and  file-loader
deal with it. vue-cli webpack of these scaffold has been configured loader, it is possible to use a relatively / module path.

Since these resources may be inlined / replication during construction / rename, they are essentially part of the source code. That is why it is recommended that
the static resource Webpack treated in  /src the directory and other source files the reasons put together. In fact, even without having to put all of them  /src/assets: You can use 模块/组件the organization to use them. For example, can be stored in a static resource directory for each placement component.

"Real" Static Assets

In contrast, the static/ files in the directory will not be processed Webpack: they will be copied directly to the final directory (by default dist/static) below. You must use an absolute path to reference these documents, this is done by the  config.js file  build.assetsPublicPath and the  build.assetsSubDirectory connection determined.

Put any  static/ files you need to reference the absolute path in the form of: /static/[filename]. If you change  assetSubDirectory the value  assets, then the path to be replaced  /assets/[filename].

 

Sometimes we need to modify nodeModule of source, modify the source code plug-ins, after the packaged file should be placed static directory. If on the other directories, webpack will be re-packaged, resulting in, for example:? Did you register the component correctly this component error

Guess you like

Origin www.cnblogs.com/yzhihao/p/11356084.html