Closed DorkForce closed 3 years ago
I'm pretty sure this was related to the fact that I wanted this plugin to run after other plugins - not necessarily the compile. Couldn't figure it out, so I created a node script to take care of it after Webpack was done.
@DorkForce Any chance of sharing your script? :D
Sure -- note that I made this generic, removing project file names, descriptions, of course:
/*
* ./.webpack/jobs.js
*/
const compileJobs = [
{
entry: "src/index-comp.js",
name: "index",
output: "dist/comp/",
description: 'Description Goes Here',
},
{
entry: "src/index-wc.js",
name: "index-wc",
output: "dist/wc/",
description: 'Description Goes Here'
}
];
const cssJobs = [
{
entry: "src/scss/all-styles.scss",
name: "all-styles-comp",
output: "dist/comp",
description: 'Description Goes Here',
},
{
entry: "src/scss/all-styles-wc.scss",
name: "all-styles-wc",
output: "dist/wc",
description: 'Description Goes Here',
}
];
module.exports = {
cssJobs,
compileJobs,
};
/*
* ./webpack.cleanup.js
*/
const path = require('path');
const jobs = require('./.webpack/jobs');
const fs = require('fs')
const utils = {
dir: (target) => {
let filesToReturn = [];
try {
const arrayOfFiles = fs.readdirSync(target)
filesToReturn = arrayOfFiles;
} catch (e) {
console.log(e)
}
return filesToReturn;
},
removeDir: function (incomingPath) {
if (fs.existsSync(incomingPath)) {
const contnts = fs.readdirSync(incomingPath);
if (contnts.length > 0) {
contnts.forEach(function (filename) {
if (fs.statSync(incomingPath + '/' + filename).isDirectory()) {
utils.removeDir(incomingPath + '/' + filename)
} else {
fs.unlinkSync(incomingPath + '/' + filename);
}
})
fs.rmdirSync(incomingPath)
} else {
fs.rmdirSync(incomingPath)
}
} else {
console.log('==>', 'Directory path not found.');
}
}
}
setTimeout(() => {
jobs.forEach((job) => {
const sourceDir = path.resolve(__dirname, 'dist', job.sourceName, 'src', 'src', 'js', 'components');
const targetDir = path.resolve(__dirname, 'dist', job.sourceName, 'src');
const components = utils.dir(sourceDir);
components.forEach((component) => {
const oldPath = (sourceDir + '/' + component).replace(/\\/g, '/');
const newPath = (targetDir + '/' + component).replace(/\\/g, '/');
fs.rename(oldPath, newPath, function (err) {
if (err) console.log('==>', err);
});
});
setTimeout(() => {
const pathToRemove = path.resolve(__dirname, 'dist', job.sourceName, 'src', 'src').replace(/\\/g, '/');
utils.removeDir(pathToRemove);
}, 500);
})
}, 2000);
SETUP: I've got some copy stuff going on in my scripts, to literally copy the source code into a /src directory of the package I intend to create. Don't ask why; I don't want to do that, but oh well. Anyway, that's working but it's copying more folders than I want. I'd like to see:
/dist/src/MyKewlComponent/
but it turns out to be/dist/src/src/js/components/MyKewlComponent/
.Problem with webpack-shell-plugin-next: I'm using this plugin to try to just MOVE the component(s) folder(s) up a few directories after the copy is done. However, it seems to process BEFORE the webpack job even runs... I see the commands being attempted, in the output, and then after that I see the results of the copy.
Portion of my code:
... I must be doing this wrong. Am I?