Я реагирую на серверный рендеринг проекта.Я использую webpack4 и babel7.Это мой файл конфигурации webpack.
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const serverConfig = {
mode: 'development',
target: 'node',
node: {
__dirname: false,
},
externals: [nodeExternals({
whitelist: [/\.css/]
})],
entry: {
'index.js': path.resolve(__dirname, 'src/server.js'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
outputPath: './fonts/',
name: '[hash].[ext]',
},
},
{
test: /\.(png|jpg|jpeg|gif|ico|svg)$/,
loader: 'file-loader',
options: {
outputPath: './img/',
name: '[name].[hash].[ext]',
},
},
{
test: /\.css$/,
use: [
'css-loader',
],
},
]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name]',
},
};
const clientConfig = {
mode: 'development',
entry: {
'client.js': path.resolve(__dirname, 'src/index.js'),
'bundle.js': path.resolve(__dirname, 'src/containers/App.js'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
outputPath: './fonts/',
name: '[hash].[ext]',
},
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|jpg|jpeg|gif|ico|svg)$/,
loader: 'file-loader',
options: {
outputPath: './img/',
name: '[name].[hash].[ext]',
},
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
]
},
],
},
output: {
path: path.resolve(__dirname, 'dist/assets'),
filename: '[name]'
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].bundle.[hash].css'
})
]
}
module.exports = [serverConfig, clientConfig];
Когда я запускаю пакетный файл в этой команде ..
node dist/index.js
Возвращает ошибки.Журнал ошибок ниже.
/home/choiyeonsuk/web/ssr-tutorial/ssr-wis/node_modules/paper/dist/node/self.js:40
var document = jsdom.jsdom('<html><body></body></html>', {
^
TypeError: jsdom.jsdom is not a function
at Object.<anonymous> (/home/choiyeonsuk/web/ssr-tutorial/ssr-wis/node_modules/paper/dist/node/self.js:40:26)
at Module._compile (internal/modules/cjs/loader.js:723:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:659:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/choiyeonsuk/web/ssr-tutorial/ssr-wis/node_modules/paper/dist/paper-full.js:35:16)
at Object.<anonymous> (/home/choiyeonsuk/web/ssr-tutorial/ssr-wis/node_modules/paper/dist/paper-full.js:16719:3)
Я думаю, это потому, что nodeExternals не исключает модули узлов ..
Есть ли какие-либо настройки для исключения узловых модулей?
спасибо.