mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Support compiling webpacker content from addons [SCI-7187]
This commit is contained in:
parent
dd5c567e50
commit
a26d26a695
|
@ -1,9 +1,39 @@
|
||||||
const { environment } = require('@rails/webpacker')
|
const { environment } = require('@rails/webpacker')
|
||||||
const { VueLoaderPlugin } = require('vue-loader')
|
const { VueLoaderPlugin } = require('vue-loader')
|
||||||
const vue = require('./loaders/vue')
|
const vue = require('./loaders/vue')
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const { basename, resolve } = require('path');
|
||||||
|
const { readdirSync } = require('fs');
|
||||||
|
|
||||||
environment.loaders.delete('nodeModules')
|
environment.loaders.delete('nodeModules')
|
||||||
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())
|
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())
|
||||||
environment.loaders.prepend('vue', vue)
|
environment.loaders.prepend('vue', vue)
|
||||||
|
|
||||||
module.exports = environment
|
// Engine pack loading based on https://github.com/rails/webpacker/issues/348#issuecomment-635480949
|
||||||
|
// Get paths to all engines' folders
|
||||||
|
const enginePaths = execSync('ls -d $PWD/addons/*').toString().split('\n').filter((p) => !!p);
|
||||||
|
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;
|
||||||
|
|
11
engines_yarn_install.js
Normal file
11
engines_yarn_install.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const { spawn, execSync } = require('child_process');
|
||||||
|
const enginePaths = execSync('ls -d $PWD/addons/*').toString().split('\n').filter((p) => !!p);
|
||||||
|
enginePaths.forEach(enginePath => {
|
||||||
|
spawn('yarn', ['install'], {
|
||||||
|
env: process.env,
|
||||||
|
cwd: enginePath,
|
||||||
|
stdio: 'inherit'
|
||||||
|
});
|
||||||
|
});
|
|
@ -20,6 +20,7 @@
|
||||||
"flow": "flow",
|
"flow": "flow",
|
||||||
"lint": "eslint ."
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
|
"postinstall": "./engines_yarn_install.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.0.0",
|
"@babel/core": "^7.0.0",
|
||||||
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
|
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
|
||||||
|
|
Loading…
Reference in a new issue