mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
wip
This commit is contained in:
parent
170d88a6d6
commit
735a349736
@ -73,8 +73,7 @@ async function copyAdmin(dest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function build({ dir, env }) {
|
async function build({ dir, env, options }) {
|
||||||
console.log('Building your app');
|
|
||||||
const cacheDir = path.resolve(dir, '.cache');
|
const cacheDir = path.resolve(dir, '.cache');
|
||||||
|
|
||||||
const pkgJSON = require(path.join(dir, 'package.json'));
|
const pkgJSON = require(path.join(dir, 'package.json'));
|
||||||
@ -97,7 +96,7 @@ async function build({ dir, env }) {
|
|||||||
const entry = path.resolve(cacheDir, 'admin', 'src', 'app.js');
|
const entry = path.resolve(cacheDir, 'admin', 'src', 'app.js');
|
||||||
const dest = path.resolve(dir, 'build');
|
const dest = path.resolve(dir, 'build');
|
||||||
|
|
||||||
const config = getWebpackConfig({ entry, dest, env });
|
const config = getWebpackConfig({ entry, dest, env, options });
|
||||||
|
|
||||||
const compiler = webpack(config);
|
const compiler = webpack(config);
|
||||||
|
|
||||||
|
@ -13,12 +13,18 @@ const alias = require('./webpack.alias.js');
|
|||||||
|
|
||||||
// TODO: parametrize
|
// TODO: parametrize
|
||||||
const URLs = {
|
const URLs = {
|
||||||
host: '/admin/',
|
|
||||||
backend: 'http://localhost:1337',
|
|
||||||
mode: 'host',
|
mode: 'host',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ({ publicPath = '/admin/', entry, dest, env }) => {
|
module.exports = ({
|
||||||
|
entry,
|
||||||
|
dest,
|
||||||
|
env,
|
||||||
|
options = {
|
||||||
|
backend: 'http://localhost:1337',
|
||||||
|
publicPath: '/admin/',
|
||||||
|
},
|
||||||
|
}) => {
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
|
|
||||||
const webpackPlugins = isProduction
|
const webpackPlugins = isProduction
|
||||||
@ -45,7 +51,7 @@ module.exports = ({ publicPath = '/admin/', entry, dest, env }) => {
|
|||||||
loader: MiniCssExtractPlugin.loader,
|
loader: MiniCssExtractPlugin.loader,
|
||||||
options: {
|
options: {
|
||||||
fallback: require.resolve('style-loader'),
|
fallback: require.resolve('style-loader'),
|
||||||
publicPath: publicPath,
|
publicPath: options.publicPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -58,7 +64,7 @@ module.exports = ({ publicPath = '/admin/', entry, dest, env }) => {
|
|||||||
entry,
|
entry,
|
||||||
output: {
|
output: {
|
||||||
path: dest,
|
path: dest,
|
||||||
publicPath: publicPath,
|
publicPath: options.publicPath,
|
||||||
// Utilize long-term caching by adding content hashes (not compilation hashes)
|
// Utilize long-term caching by adding content hashes (not compilation hashes)
|
||||||
// to compiled assets for production
|
// to compiled assets for production
|
||||||
filename: isProduction ? '[name].js' : '[name].[chunkhash].js',
|
filename: isProduction ? '[name].js' : '[name].[chunkhash].js',
|
||||||
@ -239,12 +245,14 @@ module.exports = ({ publicPath = '/admin/', entry, dest, env }) => {
|
|||||||
new SimpleProgressWebpackPlugin(),
|
new SimpleProgressWebpackPlugin(),
|
||||||
|
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
'process.env.NODE_ENV': JSON.stringify(
|
||||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
isProduction ? 'production' : 'development'
|
||||||
REMOTE_URL: JSON.stringify(URLs.host),
|
),
|
||||||
BACKEND_URL: JSON.stringify(URLs.backend),
|
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
|
||||||
|
REMOTE_URL: JSON.stringify(options.publicPath),
|
||||||
|
BACKEND_URL: JSON.stringify(options.backend),
|
||||||
MODE: JSON.stringify(URLs.mode), // Allow us to define the public path for the plugins assets.
|
MODE: JSON.stringify(URLs.mode), // Allow us to define the public path for the plugins assets.
|
||||||
PUBLIC_PATH: JSON.stringify(publicPath),
|
PUBLIC_PATH: JSON.stringify(options.publicPath),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
...webpackPlugins,
|
...webpackPlugins,
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use `server.js` to run your application without `$ strapi start`.
|
|
||||||
* To start the server, run: `$ npm start`.
|
|
||||||
*
|
|
||||||
* This is handy in situations where the Strapi CLI is not relevant or useful.
|
|
||||||
*/
|
|
||||||
const strapi = require('strapi');
|
|
||||||
|
|
||||||
strapi({
|
|
||||||
appPath: __dirname,
|
|
||||||
}).start();
|
|
@ -145,9 +145,13 @@ program
|
|||||||
.action(getScript('generate'));
|
.action(getScript('generate'));
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('build')
|
.command('build [dir]')
|
||||||
|
.option('--env [env]', 'Build for which env')
|
||||||
.description('Builds the strapi admin app')
|
.description('Builds the strapi admin app')
|
||||||
.action(getScript('build'));
|
.action((dir, options) => {
|
||||||
|
const env = options.env || 'production';
|
||||||
|
getScript('build')({ dir, env });
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize help argument
|
* Normalize help argument
|
||||||
|
@ -1,9 +1,35 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const { green } = require('chalk');
|
||||||
const strapiAdmin = require('strapi-admin');
|
const strapiAdmin = require('strapi-admin');
|
||||||
|
const { cli } = require('strapi-utils');
|
||||||
|
|
||||||
// build script shoul only run in production mode
|
|
||||||
process.env.NODE_ENV = 'production';
|
process.env.NODE_ENV = 'production';
|
||||||
module.exports = () => {
|
// build script shoul only run in production mode
|
||||||
return strapiAdmin.build({ dir: process.cwd(), env: 'production' });
|
module.exports = ({ dir = '', env }) => {
|
||||||
|
// Check that we're in a valid Strapi project.
|
||||||
|
if (!cli.isStrapiApp()) {
|
||||||
|
return console.log(
|
||||||
|
`⛔️ ${cyan('strapi start')} can only be used inside a Strapi project.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const appPath = path.join(process.cwd(), dir);
|
||||||
|
|
||||||
|
console.log(`Building your app with ${green(env)} configuration`);
|
||||||
|
|
||||||
|
// Require server configurations
|
||||||
|
const server = require(path.resolve(
|
||||||
|
appPath,
|
||||||
|
'config',
|
||||||
|
'environments',
|
||||||
|
env,
|
||||||
|
'server.json'
|
||||||
|
));
|
||||||
|
|
||||||
|
return strapiAdmin.build({
|
||||||
|
dir: process.cwd(),
|
||||||
|
env: 'production',
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,7 @@ const _ = require('lodash');
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { cyan } = require('chalk');
|
const { cyan } = require('chalk');
|
||||||
const chokidar = require('chokidar');
|
const chokidar = require('chokidar');
|
||||||
const buildApp = require('./build');
|
const strapiAdmin = require('strapi-admin');
|
||||||
|
|
||||||
// Logger.
|
// Logger.
|
||||||
const { cli, logger } = require('strapi-utils');
|
const { cli, logger } = require('strapi-utils');
|
||||||
@ -28,7 +28,9 @@ const { cli, logger } = require('strapi-utils');
|
|||||||
* (fire up the application in our working directory).
|
* (fire up the application in our working directory).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = async function(appPath = '') {
|
module.exports = async function(dir = '.') {
|
||||||
|
process.env.NODE_ENV = 'development';
|
||||||
|
|
||||||
// Check that we're in a valid Strapi project.
|
// Check that we're in a valid Strapi project.
|
||||||
if (!cli.isStrapiApp()) {
|
if (!cli.isStrapiApp()) {
|
||||||
return console.log(
|
return console.log(
|
||||||
@ -36,33 +38,29 @@ module.exports = async function(appPath = '') {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
appPath = path.join(process.cwd(), appPath);
|
const appPath = path.join(process.cwd(), dir);
|
||||||
|
|
||||||
|
// Require server configurations
|
||||||
|
const server = require(path.resolve(
|
||||||
|
appPath,
|
||||||
|
'config',
|
||||||
|
'environments',
|
||||||
|
'development',
|
||||||
|
'server.json'
|
||||||
|
));
|
||||||
|
|
||||||
if (!fs.existsSync(path.resolve(appPath, 'build'))) {
|
if (!fs.existsSync(path.resolve(appPath, 'build'))) {
|
||||||
await buildApp();
|
await strapiAdmin.build({
|
||||||
|
dir: process.cwd(),
|
||||||
|
env: 'production',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const strapiInstance = strapi({ appPath });
|
const strapiInstance = strapi({ appPath });
|
||||||
|
|
||||||
// Set NODE_ENV
|
if (_.get(server, 'autoReload.enabled') === true) {
|
||||||
if (_.isEmpty(process.env.NODE_ENV)) {
|
|
||||||
process.env.NODE_ENV = 'development';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Require server configurations
|
|
||||||
const server = require(path.resolve(
|
|
||||||
appPath,
|
|
||||||
'config',
|
|
||||||
'environments',
|
|
||||||
'development',
|
|
||||||
'server.json'
|
|
||||||
));
|
|
||||||
|
|
||||||
if (
|
|
||||||
process.env.NODE_ENV === 'development' &&
|
|
||||||
_.get(server, 'autoReload.enabled') === true
|
|
||||||
) {
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
cluster.on('message', (worker, message) => {
|
cluster.on('message', (worker, message) => {
|
||||||
switch (message) {
|
switch (message) {
|
||||||
@ -101,27 +99,19 @@ module.exports = async function(appPath = '') {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return strapiInstance.start(afterwards);
|
return strapiInstance.start();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strapiInstance.start(afterwards);
|
strapiInstance.start();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function afterwards(err, strapiInstance) {
|
|
||||||
if (err) {
|
|
||||||
logger.error(err.stack ? err.stack : err);
|
|
||||||
|
|
||||||
strapiInstance ? strapiInstance.stop() : process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init file watching to auto restart strapi app
|
* Init file watching to auto restart strapi app
|
||||||
* @param {Object} options - Options object
|
* @param {Object} options - Options object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user