2018-07-25 05:37:38 -04:00
|
|
|
const path = require('path');
|
2018-07-27 14:26:03 -04:00
|
|
|
const webpack = require('webpack');
|
2018-07-28 17:11:29 -04:00
|
|
|
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
|
2018-09-06 16:59:18 -04:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2018-07-27 14:26:03 -04:00
|
|
|
const pkg = require('./package.json');
|
2019-03-16 15:44:29 -07:00
|
|
|
const { getConfig, plugins } = require('../../scripts/webpack');
|
|
|
|
const baseWebpackConfig = getConfig({ baseOnly: true });
|
2018-07-23 23:40:48 -04:00
|
|
|
|
2018-07-27 14:26:03 -04:00
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
2019-03-16 15:44:29 -07:00
|
|
|
console.log(`${pkg.version}${isProduction ? '' : '-dev'}`);
|
2018-07-27 14:26:03 -04:00
|
|
|
|
|
|
|
const baseConfig = {
|
2019-03-16 15:44:29 -07:00
|
|
|
...baseWebpackConfig,
|
2018-07-27 14:26:03 -04:00
|
|
|
context: path.join(__dirname, 'src'),
|
|
|
|
entry: './index.js',
|
|
|
|
plugins: [
|
2018-07-28 17:11:29 -04:00
|
|
|
...Object.entries(plugins)
|
2018-08-07 14:46:54 -06:00
|
|
|
.filter(([key]) => key !== 'friendlyErrors')
|
|
|
|
.map(([, plugin]) => plugin()),
|
2018-07-27 14:26:03 -04:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
NETLIFY_CMS_VERSION: JSON.stringify(`${pkg.version}${isProduction ? '' : '-dev'}`),
|
|
|
|
NETLIFY_CMS_CORE_VERSION: null,
|
|
|
|
}),
|
2018-07-28 17:11:29 -04:00
|
|
|
new FriendlyErrorsWebpackPlugin({
|
|
|
|
compilationSuccessInfo: {
|
|
|
|
messages: ['Netlify CMS is now running at http://localhost:8080'],
|
|
|
|
},
|
|
|
|
}),
|
2019-03-16 15:44:29 -07:00
|
|
|
new CopyWebpackPlugin([{ from: '../shims/cms.css', to: './' }]),
|
2018-07-27 14:26:03 -04:00
|
|
|
],
|
2018-07-28 17:11:29 -04:00
|
|
|
devServer: {
|
|
|
|
contentBase: '../../dev-test',
|
|
|
|
watchContentBase: true,
|
2019-03-22 18:18:30 -04:00
|
|
|
publicPath: '/dist/',
|
2018-07-28 17:11:29 -04:00
|
|
|
quiet: true,
|
|
|
|
host: 'localhost',
|
|
|
|
port: 8080,
|
|
|
|
},
|
2018-07-27 14:26:03 -04:00
|
|
|
};
|
|
|
|
|
2018-07-28 17:11:29 -04:00
|
|
|
if (isProduction) {
|
|
|
|
module.exports = [
|
|
|
|
baseConfig,
|
2018-07-27 11:08:17 -04:00
|
|
|
|
2018-07-28 17:11:29 -04:00
|
|
|
/**
|
|
|
|
* Output the same script a second time, but named `cms.js`, and with a
|
|
|
|
* deprecation notice.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
...baseConfig,
|
2018-09-06 16:59:18 -04:00
|
|
|
entry: [path.join(__dirname, 'shims/deprecate-old-dist.js'), baseConfig.entry],
|
2018-07-28 17:11:29 -04:00
|
|
|
output: {
|
|
|
|
...baseConfig.output,
|
2019-03-16 15:44:29 -07:00
|
|
|
filename: 'cms.js',
|
2018-07-28 17:11:29 -04:00
|
|
|
},
|
2018-07-27 11:08:17 -04:00
|
|
|
},
|
2018-07-28 17:11:29 -04:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
module.exports = baseConfig;
|
|
|
|
}
|