我正在尝试将copy-webpack-plugin添加到我的asp .net核心2-angular5 Web应用程序中。我已经安装了copy-webpack-plugin。我在运行webpack.js时收到以下错误:
new webpack.CopyWebpackPlugin(
^
TypeError: webpack.CopyWebpackPlugin is not a constructor
这是webpack.config.js
const CopyWebpackPlugin = require('copy-webpack-plugin').CopyWebpackPlugin;
....
const clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot.browser.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.CopyWebpackPlugin(
{ from: './ClientApp/assets', to: './wwwroot/dist/assets', toType : 'dir' }
),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
exclude: ['./**/*.server.ts']
})
])
});
我该如何解决这个错误?
请试试:
const CopyWebpackPlugin = require('copy-webpack-plugin');
我认为没有名为“CopyWebpackPlugin”的命名导出
用它来实例化它
new CopyWebpackPlugin([ ...patterns ], options)
文件:https://github.com/webpack-contrib/copy-webpack-plugin
说明:
当你写作
new webpack.CopyWebpackPlugin()
您假设webpack附带了CopyWebpackPlugin并在其命名空间下发布它,但webpack在其命名空间下没有CopyWebPackPlugin。这就是你必须单独安装和导入它的原因