我正在尝试使用以下webpack.config.js对Webpack反应项目:
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: "production",
entry: "./app/src/plugin.js",
output: {
filename: "build/static/js/bundle-project.min.js",
libraryTarget: "commonjs"
},
node: {
fs: "empty"
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.svg$/,
loader: "svg-inline-loader"
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: "url-loader?limit=100000"
},
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-react", "@babel/preset-env"],
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-modules-commonjs"
]
}
}
]
},
plugins: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 6
}
})
],
resolve: {
alias: {
utils: path.resolve("./src/utils"),
"user-abilities": path.resolve("./src/user-abilities"),
shared: path.resolve("./src/shared"),
components: path.resolve("./src/components"),
store: path.resolve("./src/store")
}
},
externals: {
react: "commonjs react"
}
};
然后我正在做npm,将软件包发布并导入到其他项目中 使用
从@ my-repo-package导入Main
尝试在其他项目中渲染包时出现此错误: