knockout.js 在Webpack中添加第三方库

6kkfgxo0  于 2022-11-10  发布在  Webpack
关注(0)|答案(1)|浏览(192)

我正在使用webpack ...我想在webpack.config.js文件中使用第三方库(knockoutjs库),库保存在我的本地目录中
我试过使用

  1. const ojL10n = require("D:/SVN/trunk/core/channel/framework/tmp/ojL10n.js")

但我得到错误...定义未在D中定义
这是我配置文件

  1. "use strict";
  2. require("amd-loader");
  3. const webpack = require("webpack"),
  4. path = require("path");
  5. ojL10n = require("./tmp/ojL10n.js"), //library stored in local
  6. text = require("./tmp/text.js"), //library stored in local
  7. webpackConfigurationObject = {
  8. entry: "./entryModule.js",
  9. target: "node",
  10. mode: "development",
  11. node: {
  12. __dirname: false
  13. },
  14. resolve: {
  15. alias: {
  16. text : text,
  17. ojL10n : ojL10n
  18. },
  19. extensions: [".ts",".js", ".json"]
  20. },
  21. output: {
  22. path: path.join(__dirname, "dest"),
  23. filename: "combinedFile.js",
  24. library: "combinedFile",
  25. libraryTarget: "commonjs2"
  26. },
  27. module: {
  28. rules: [{
  29. test: /\.ts$/,
  30. include: /src/,
  31. exclude: /(node_modules)|(dist)/,
  32. use: {
  33. loader: "babel-loader"
  34. },
  35. parser: { amd: false }
  36. }]
  37. },
  38. externals: {
  39. jquery: {
  40. commonjs2 : "jQuery"
  41. },
  42. knockout: {
  43. commonjs2 : "knockout"
  44. }
  45. }
  46. };
  47. const compiler = webpack(webpackConfigurationObject),
  48. compiler.run(complete);
kcugc4gi

kcugc4gi1#

这个问题我有答案了。

  1. resolveLoader: {
  2. // This adds ./loaders/ to the list of folders where Webpack is looking for loaders
  3. modules: ["node_modules", path.resolve(__dirname, "./loaders")],
  4. alias: {
  5. ojL10n: "ojL10n-loader",
  6. text: "text-loader"
  7. }

将resolveLoader添加到webpack.config.js文件中

相关问题