2018-11-22 05:05:33 +08:00
|
|
|
const { environment } = require('@rails/webpacker')
|
2021-08-05 19:15:49 +08:00
|
|
|
const { VueLoaderPlugin } = require('vue-loader')
|
|
|
|
const vue = require('./loaders/vue')
|
2023-02-02 16:35:10 +08:00
|
|
|
const { execSync } = require('child_process');
|
|
|
|
const { basename, resolve } = require('path');
|
|
|
|
const { readdirSync } = require('fs');
|
2018-11-22 05:05:33 +08:00
|
|
|
|
2019-08-08 20:03:15 +08:00
|
|
|
environment.loaders.delete('nodeModules')
|
2021-08-05 19:15:49 +08:00
|
|
|
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())
|
|
|
|
environment.loaders.prepend('vue', vue)
|
2019-07-02 20:37:05 +08:00
|
|
|
|
2023-02-02 16:35:10 +08:00
|
|
|
// Engine pack loading based on https://github.com/rails/webpacker/issues/348#issuecomment-635480949
|
|
|
|
// Get paths to all engines' folders
|
2023-02-14 17:43:55 +08:00
|
|
|
console.log('Including packs from addons...');
|
|
|
|
|
|
|
|
let enginePaths = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
enginePaths = execSync('ls -d $PWD/addons/*').toString().split('\n').filter((p) => !!p);
|
|
|
|
} catch {
|
|
|
|
console.log('Unable to find any addons.')
|
|
|
|
}
|
|
|
|
|
2023-02-02 16:35:10 +08:00
|
|
|
enginePaths.forEach((path) => {
|
|
|
|
const packsFolderPath = `${path}/app/javascript/packs`;
|
|
|
|
|
|
|
|
let entryFiles;
|
|
|
|
try {
|
|
|
|
entryFiles = readdirSync(packsFolderPath);
|
|
|
|
console.log(`Found packs in ${path}`);
|
|
|
|
} catch {
|
|
|
|
console.log(`No packs in ${path}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entryFiles.forEach((file) => {
|
|
|
|
// File name without .js
|
|
|
|
const name = basename(file, '.js');
|
|
|
|
const entryPath = `${packsFolderPath}/${file}`;
|
|
|
|
|
|
|
|
environment.entry.set(name, entryPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Otherwise babel won't transpile the file
|
|
|
|
environment.loaders.get('babel').include.push(`${path}/app/javascript`);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = environment;
|