Create build script

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-06-28 09:51:41 +02:00
parent c7681b165d
commit 62b4cc257e
2 changed files with 68 additions and 0 deletions

View File

@ -7,6 +7,7 @@
"url": "git://github.com/strapi/strapi.git"
},
"scripts": {
"prepublishOnly": "node ./scripts/build.js",
"test": "echo \"no tests yet\"",
"develop": "webpack serve --config webpack.config.dev.js --progress profile",
"develop:ce": "STRAPI_DISABLE_EE=true webpack serve --config webpack.config.dev.js --progress profile",

View File

@ -0,0 +1,67 @@
'use strict';
const path = require('path');
const webpack = require('webpack');
const webpackConfig = require('../webpack.config');
const buildAdmin = async () => {
const entry = path.join(__dirname, '..', 'admin', 'src');
const dest = path.join(__dirname, '..', 'build');
const args = {
entry,
dest,
env: 'production',
optimize: true,
options: {
backend: 'http://localhost:1337',
adminPath: '/admin/',
features: [],
},
useEE: false,
};
const compiler = webpack(webpackConfig(args));
console.log('Building the admin panel');
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
let messages;
if (err) {
if (!err.message) {
return reject(err);
}
messages = {
errors: [err.message],
warnings: [],
};
} else {
messages = stats.toJson({ all: false, warnings: true, errors: true });
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1;
}
return reject(new Error(messages.errors.join('\n\n')));
}
return resolve({
stats,
warnings: messages.warnings,
});
});
});
};
buildAdmin()
.then(() => {
process.exit();
})
.catch(err => {
console.error(err);
process.exit(1);
});