问题描述
我有一个基于 javascript 的项目,其中包含一个已编译的打字稿项目。 此打字稿项目依赖于项目文件夹外的打字稿文件。但是,不应将这些外部文件编译到构建中。它们应该被视为黑匣子。这些文件已经加载到“第一个”项目中,我不希望它被加载两次。
这是我的 webpack 配置。
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const path = require("path")
module.exports = {
optimization: {
minimize: false
},entry: {
'code': './src/code.ts'
},plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['public/build']
}),],output: {
path: __dirname + '/public',filename: 'build/[name].js',},module: {
rules: [
{
test: /\.ts?$/,loader: 'ts-loader',exclude: [/node_modules/,path.resolve("../../../../")],{
test: /\.css$/i,loader: 'css-loader'
},{
test: /\.js$/i,loader: 'style-loader',exclude: /node_modules/,{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|json|xml|ico|cur|ani)$/,use: ['file-loader?name=[path][name].[ext]'],]
},resolve: {
extensions: [
'.ts','.js','.json',};
对于“ts-loader”,我试图排除这些文件“../../../../”,实际上这似乎有效。但是,我将收到这些排除文件的编译器错误,这是我以前没有收到的。
它似乎仍在尝试导入这些文件,但再也找不到它们了,因此它不会忽略它们,而是会引发错误。
是否有任何选项可以忽略这些数组并将这些排除的导入视为黑盒或“任何”? 同样的行为发生在 css-loader 上。 我使用的是 webpack 5.17.0 和 typescript 4.1.3。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)