I'm creating a frontend project in VueJS 2 (and Vue-CLI 3) that will be used by different clients and I would like to be able to import basically everything I need (JS files like mixins and component code and CSS/LESS files) during the webpack build process parametrically based on the CID that would be stored in:
1) the Vue .env file or
2) somewhere in the webpack config file or
3) passed as a parameter to npm run watch
and npm run build
.
I've searched about many solutions (Webpack plugins etc.) but none of them are simple or elegant nor am I really able to understand the inner workings of the Webpack to implement those solutions and most are related to the dynamic loading not the dynamic build process.
Different clients require different code and styling so for example:
<template>...</template>
<script src="./component-code.js"></script>
<style src="@/styles/component-style.less"></style>
These paths would need to turn into something along these lines:
<template>...</template>
<script src="./CLIENTID/component-code.js"></script>
<style src="@/styles/CLIENTID/component-style.less"></style>
...so that the Webpack can replace these CLIENTID
references when compiling with real folder names whatever those may be. This would also have to work for any other file paths (e.g. when using statements like import something from "./path/CLIENTID/to/file";
).
What would be the easiest solution to injecting such a variable into the build process? Thanks!