【发布时间】:2021-11-21 17:47:46
【问题描述】:
我有一个 Vue 项目,它具有从 Vue CLI 生成的标准 webpack 配置。这给出了项目目录结构,例如:
public\
css\
images\
index.html
src\
tests\
package.json
etc...
所以默认的静态资产目录是项目目录根目录下的public\。现在我想指定另一个静态目录(它将位于src\ 中的某处),以便在构建时合并这两个目录的内容。如果文件冲突,src\ 中的文件应该覆盖public\ 中的文件。
如何使用 webpack 做到这一点?
我需要这个的原因是因为我想为不同的客户制作单独的版本。每个客户都将拥有自己的特定资产和组件,我计划将它们放在src\ 的某个位置。例如:
public\ // shared static assets
src\
components\ // shared stuff for all customers
store\
...etc
customer1\ // customer1 specific stuff below this level
public\ // merge these with shared static assets and overwrite if necessary
components\
store\
index.js
customer2\ // customer2 specific stuff below this level
public\
components\
store\
index.js
因此,当我运行 npm run build --customer=customer1 时,我只想在捆绑包中获取 shared + customer1 的东西。我几乎通过webpack alias config 为客户的组件、商店和其他非静态内容解决了这个问题,我想知道如何为public 目录中的静态资产做到这一点?
【问题讨论】:
标签: javascript reactjs vue.js webpack frontend