webpack增强溶解插件不起作用
我正在尝试遵循开发人员主题的说明,请 这行不通。我要解释这个问题,但首先让我看看我的项目结构。
我的文件结构如下:
---dist
---mylib
index.ts
lib.ts
---mylib1
index.ts
lib.ts
---src
index.html
index.ts
package.json
tsconfig.json
webpack.config.js
mylib/index.ts
export * from './lib';
mylib/lib.ts
export function sayHi() {
alert("hi");
}
mylib1/index.ts
export * from './lib';
mylib1/lib.ts
export function sayHi1() {
alert("hi1");
}
src/index.ts
import {sayHi1} from '@mylibs';
console.log("Hello World!");
sayHi1();
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"baseUrl": ".",
"allowJs": true,
"paths": {
"@mylibs": ["mylib", "mylib1"]
}
},
"files": ["src/index.ts"]
}
webpack.config.json package.json:
// Generated using webpack-cli https://github.com/webpack/webpack-cli
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
const isProduction = process.env.NODE_ENV == "production";
const stylesHandler = "style-loader";
const config = {
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, "dist"),
},
devServer: {
open: true,
host: "localhost",
},
plugins: [
new HtmlWebpackPlugin({
template: "index.html",
}),
],
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
loader: "ts-loader",
exclude: ["/node_modules/"],
options: {
transpileOnly: true,
},
},
{
test: /\.css$/i,
use: [stylesHandler, "css-loader"],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: "asset",
},
// Add your rules for custom modules here
// Learn more about loaders from https://webpack.js.org/loaders/
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
plugins: [
new AliasPlugin(
"described-resolve",
[{ name: "@mylibs", alias: ["../mylib", "../mylib1"] }],
"resolve"
),
]
// alias: {
// "@mylibs": ["../mylib", "../mylib1"] // also didn't work
// },
},
};
module.exports = () => {
if (isProduction) {
config.mode = "production";
} else {
config.mode = "development";
}
return config;
};
错误消息是:
export 'sayHi1' (imported as 'sayHi1') was not found in '@mylibs' (possible exports: sayHi)
如果我尝试导入 sayhi
它将起作用,或者即使我交换了 [“ ../ mylib”,“ ../mylib1”的位置]
在 Aliasplugin中
它也将起作用。看来它只会搜索第一个路径。
任何帮助都将不胜感激,因为我正在执行文档中所说的一切。
完整的WebPack输出消息,如果有帮助:
asset main.js 243 bytes [compared for emit] [minimized] (name: main)
asset index.html 201 bytes [compared for emit]
orphan modules 72 bytes [orphan] 2 modules
runtime modules 274 bytes 1 module
./src/index.ts + 1 modules 100 bytes [built] [code generated]
WARNING in ./src/index.ts 3:0-6
export 'sayHi1' (imported as 'sayHi1') was not found in '@mylibs' (possible exports: sayHi)
webpack 5.72.1 compiled with 1 warning in 755 ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论