Skip to content

Commit

Permalink
🔧 For CDN hosting, ensure user-data is coppied over during build
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Apr 16, 2024
1 parent c1f23d2 commit b711f77
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@vue/cli-service": "^4.5.19",
"@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^10.0.1",
"copy-webpack-plugin": "6.4.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-vue": "^7.9.0",
Expand Down
26 changes: 26 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* See docs for all config options: https://cli.vuejs.org/config
*/

const fs = require('fs');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

// Get app mode: production, development or test
const mode = process.env.NODE_ENV || 'production';
Expand All @@ -20,9 +22,33 @@ const publicPath = process.env.BASE_URL || '/';
// Should enable Subresource Integrity (SRI) on link and script tags
const integrity = process.env.INTEGRITY === 'true';

// When deploying as a static site, we must ensure user-data is copied over
class ConditionalCopyPlugin {
constructor(options) {
this.options = options;
}

apply(compiler) {
compiler.hooks.beforeRun.tapAsync('ConditionalCopyPlugin', (_compilation, callback) => {
const targetDir = path.resolve(compiler.options.output.path, this.options.to);
if (!fs.existsSync(targetDir)) {
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, this.options.from), to: targetDir },
],
}).apply(compiler);
}
callback();
});
}
}

// Webpack Config
const configureWebpack = {
mode,
plugins: [
new ConditionalCopyPlugin({ from: 'user-data', to: 'user-data' }),
],
module: {
rules: [
{ test: /.svg$/, loader: 'vue-svg-loader' },
Expand Down
Loading

0 comments on commit b711f77

Please sign in to comment.