build: expose local dev server port (#3221)

This commit is contained in:
Erez Rokah 2020-02-10 17:49:53 +02:00 committed by GitHub
parent d61841f9db
commit ee7445d49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') });
const webpack = require('webpack'); const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
@ -8,6 +10,8 @@ const baseWebpackConfig = getConfig({ baseOnly: true });
const isProduction = process.env.NODE_ENV === 'production'; const isProduction = process.env.NODE_ENV === 'production';
console.log(`${pkg.version}${isProduction ? '' : '-dev'}`); console.log(`${pkg.version}${isProduction ? '' : '-dev'}`);
const devServerPort = parseInt(process.env.NETLIFY_CMS_DEV_SERVER_PORT || `${8080}`);
const baseConfig = { const baseConfig = {
...baseWebpackConfig, ...baseWebpackConfig,
plugins: [ plugins: [
@ -19,7 +23,7 @@ const baseConfig = {
}), }),
new FriendlyErrorsWebpackPlugin({ new FriendlyErrorsWebpackPlugin({
compilationSuccessInfo: { compilationSuccessInfo: {
messages: ['Netlify CMS is now running at http://localhost:8080'], messages: [`Netlify CMS is now running at http://localhost:${devServerPort}`],
}, },
}), }),
new CopyWebpackPlugin([{ from: './shims/cms.css', to: './' }]), new CopyWebpackPlugin([{ from: './shims/cms.css', to: './' }]),
@ -30,7 +34,7 @@ const baseConfig = {
publicPath: '/dist/', publicPath: '/dist/',
quiet: true, quiet: true,
host: '0.0.0.0', host: '0.0.0.0',
port: 8080, port: devServerPort,
}, },
}; };