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

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

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

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

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

"use strict";

require("amd-loader");

const webpack = require("webpack"),
path = require("path");

ojL10n = require("./tmp/ojL10n.js"), //library stored in local
text = require("./tmp/text.js"), //library stored in local

 webpackConfigurationObject = {
    entry: "./entryModule.js",
    target: "node",
    mode: "development",
    node: {
        __dirname: false
    },
    resolve: {
        alias: {
            text : text,
            ojL10n : ojL10n
        },
        extensions: [".ts",".js", ".json"]
    },
    output: {
        path: path.join(__dirname, "dest"),
        filename: "combinedFile.js",
        library: "combinedFile",
        libraryTarget: "commonjs2"
    },
    module: {
        rules: [{
            test: /\.ts$/,
            include: /src/,
            exclude: /(node_modules)|(dist)/,
            use: {
                loader: "babel-loader"
            },
            parser: { amd: false }
        }]
    },
    externals: {
        jquery: {
            commonjs2 : "jQuery"
        },
        knockout: {
            commonjs2 : "knockout"
        }
    }
};

const compiler = webpack(webpackConfigurationObject),

compiler.run(complete);
kcugc4gi

kcugc4gi1#

这个问题我有答案了。

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

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

相关问题