mirror of
https://github.com/zhigang1992/server-components-demo.git
synced 2026-01-12 22:52:14 +08:00
Co-authored-by: Dan Abramov <dan.abramov@me.com> Co-authored-by: Sebastian Markbåge <sema@fb.com> Co-authored-by: Joseph Savona <josephsavona@users.noreply.github.com> Co-authored-by: Andrew Clark <git@andrewclark.io>
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
const rimraf = require('rimraf');
|
|
const webpack = require('webpack');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const ReactServerWebpackPlugin = require('react-server-dom-webpack/plugin');
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
rimraf.sync(path.resolve(__dirname, '../build'));
|
|
webpack(
|
|
{
|
|
mode: isProduction ? 'production' : 'development',
|
|
devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
|
|
entry: [path.resolve(__dirname, '../src/index.client.js')],
|
|
output: {
|
|
path: path.resolve(__dirname, '../build'),
|
|
filename: 'main.js',
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
use: 'babel-loader',
|
|
exclude: /node_modules/,
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
inject: true,
|
|
template: path.resolve(__dirname, '../public/index.html'),
|
|
}),
|
|
new ReactServerWebpackPlugin({isServer: false}),
|
|
],
|
|
},
|
|
(err, stats) => {
|
|
if (err) {
|
|
console.error(err.stack || err);
|
|
if (err.details) {
|
|
console.error(err.details);
|
|
}
|
|
process.exit(1);
|
|
return;
|
|
}
|
|
const info = stats.toJson();
|
|
if (stats.hasErrors()) {
|
|
console.log('Finished running webpack with errors.');
|
|
info.errors.forEach((e) => console.error(e));
|
|
process.exit(1);
|
|
} else {
|
|
console.log('Finished running webpack.');
|
|
}
|
|
}
|
|
);
|