首页 > 解决方案 > 原始捆绑文件时webpack与静态关键字冲突

问题描述

编辑

冲突结果是它不喜欢静态这个词,或者它不喜欢 Map。


我尝试关闭静态并且仍然抛出错误,看起来它不喜欢Map.

webpack.config

const path = require("path");
const RawBundlerPlugin = require("webpack-raw-bundler");

module.exports = {
    entry: [
        "./src/header.txt",
        "./src/Test.js",
        "./src/footer.txt"
    ],
    output: {
        filename: "lib.js",
        path: path.resolve(__dirname, "bin")
    },
    module: {
        rules: [
            { test: /\.txt$/, use: "raw-loader" }
        ]
    },
    plugins: [
        new RawBundlerPlugin({
            readEncoding: "utf-8",
            bundles: [ "lib" ],
            "lib": [
                "src/header.txt",
                "src/Test.js",
                "src/footer.txt"
            ]
        })
    ],
    mode: "none",
    watch: true,
    watchOptions: {
        ignored: /node_modules/
    }
};

包含单词 static 的源测试文件

class Test {

    // ...

    /**
     *
     * @type {Map<string, string>}
     */
    static myMap = new Map();

}

指向静态的错误抛出

Module parse failed: Unexpected token (74:23)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|      * @type {Map<string, string>}
|      */

标签: webpackjsdoc

解决方案


推荐阅读