Ошибка ссылки при использовании DllReferencePlugin для Webpack 4
Я получаю следующую ошибку:
external "vendor_ae909ad1414a86916ed0":1 Uncaught ReferenceError: vendor_ae909ad1414a86916ed0 is not defined
at Object.dll-reference vendor_ae909ad1414a86916ed0 (external "vendor_ae909ad1414a86916ed0":1)
at __webpack_require__ (bootstrap:724)
at fn (bootstrap:101)
at Object../node_modules/event-source-polyfill/src/eventsource.js (eventsource.js from dll-reference vendor_ae909ad1414a86916ed0:1)
at __webpack_require__ (bootstrap:724)
at fn (bootstrap:101)
at Object.0 (webviewer-beta-ui.min.js:51732)
at __webpack_require__ (bootstrap:724)
at ./client/assets sync recursive ^\.\/.*\.svg$.map../No color.svg (bootstrap:791)
at bootstrap:791
Webpack.config.vendor.js -
/* eslint-disable */
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const merge = require('webpack-merge');
const isDebug = global.DEBUG === false ? false : !process.argv.includes('--release');
const config = (isDebug) => {
const isDevBuild = isDebug;
const extractCSS = new MiniCssExtractPlugin({filename: 'vendor.css'});
const sharedConfig = {
mode: isDevBuild ? 'development' : 'production',
stats: { modules: false },
resolve: { extensions: [ '.js' ] },
module: {
rules: [
{ test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }
]
},
entry: {
vendor: [
'domain-task',
'event-source-polyfill',
'history',
'react',
'react-dom',
'react-router-dom',
'react-redux',
'redux',
'redux-thunk',
'react-router-redux',
'jquery'
],
},
output: {
publicPath: 'dist/',
filename: '[name].js',
library: '[name]_[hash]',
},
plugins: [
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
new webpack.NormalModuleReplacementPlugin(/\/iconv-loader$/, require.resolve('node-noop')) // Workaround for https://github.com/andris9/encoding/issues/16
]
};
const clientBundleConfig = merge(sharedConfig, {
output: { path: path.join(__dirname, 'wwwroot', 'dist') },
module: {
rules: [
{
test: /\.css(\?|$)/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
minimize: isDevBuild,
sourceMap: isDevBuild
}
}
]
}
]
},
plugins: [
extractCSS,
new webpack.DllPlugin({
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
name: '[name]_[hash]'
})
],
optimization: {
minimize: !isDevBuild
},
});
return [clientBundleConfig];
};
module.exports = config(isDebug);
Webpack.config.js -
/* eslint-disable */
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const merge = require('webpack-merge');
const isDebug = global.DEBUG === false ? false : !process.argv.includes('--release');
const config = (isDebug) => {
const isDevBuild = isDebug;
// Configuration in common to both client-side and server-side bundles
const sharedConfig = () => ({
mode: isDevBuild ? 'development' : 'production',
stats: { modules: false },
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /\.tsx?$/, include: /client/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: false,
plugins: ['react-hot-loader/babel'],
},
},
'awesome-typescript-loader?silent=true', // (or awesome-typescript-loader)
]
},
{ test: /\.jsx?$/, include: /client/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
plugins: ['react-hot-loader/babel'],
},
},
]
},
{ test: /\.(png|jpg|jpeg|gif)$/, use: 'url-loader?limit=25000' },
{
test: /\.scss$/, include: /client/,
use: [
'style-loader',
'css-loader',
'sass-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [ require('autoprefixer')() ]
}
}
],
},
{
test: /\.svg$/,
use: [
'svg-sprite-loader',
'svg-fill-loader',
'svgo-loader'
]
}
]
},
plugins: [new CheckerPlugin()]
});
// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = './wwwroot/dist/webviewer-ui-beta';
const clientBundleConfig = merge(sharedConfig(), {
entry: { 'webviewer-beta-ui.min': './client/src/boot-client.js' },
module: {
rules: [
{ test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
minimize: isDevBuild,
sourceMap: isDevBuild
}
}
]
}
]
},
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new CopyWebpackPlugin([
{
from: './client/assets',
to: '../assets'
},
{
from: './client/i18n',
to: '../i18n'
},
{
from: './client/webviewer/libs',
to: './libs'
},
{
from: './client/src/index.html',
to: './'
}
]),
// new MiniCssExtractPlugin({filename : 'site.css'}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(path.join(__dirname, 'wwwroot', 'dist', 'vendor-manifest.json'))
})
],
optimization: {
minimize: !isDevBuild
},
devtool: isDevBuild ? 'inline-source-map' : 'source-map'
});
return [clientBundleConfig];
};
module.exports = config(isDebug);
Моя папка дистрибутива выглядит так:
Я основал проект на - https://github.com/Luteceo/aspnet-starter-kit-2.0
Я удалил все prerendering и части сервера из конфигов../client/assets - это папка, заполненная файлами *.svg, которая копируется в 'dist / assets'.
Я видел, где это может быть путевой ошибкой, или забыть добавить зависимость, или просто не полностью настроить Webpack с помощью плагина DLL. Просто не знаю, как отлаживать это сам.