Convert at built-time symbols to their string representation. Basically this plugin allows to retain the symbol name as a string after a mangling or uglification compiler pass.
npm install webpack-buildtime-symbols --save-dev
or
yarn add -D webpack-buildtime-symbols
webpack.config.js
const BuildtimeSymbolsPlugin = require("webpack-buildtime-symbols/lib/plugin");
module.exports = {
plugins: [new BuildtimeSymbolsPlugin()],
};
any-file.js|ts
import {BUILDTIME_SYMBOL_TO_STRING} from "webpack-buildtime-symbols";
import {ClassName} from "another-place";
console.log("Runtime: ", BUILDTIME_SYMBOL_TO_STRING(ClassName));
After build/minification/uglification the produced result is equivalent to:
console.log("Runtime: ", "ClassName");
Note: webpack 5 support is supposed but not verified. Import of BUILDTIME_SYMBOL_TO_STRING is not supported for sure right now.
any-file.js|ts
// No import for BUILDTIME_SYMBOL_TO_STRING is currently supported
import {ClassName} from "another-place";
console.log("Runtime: ", BUILDTIME_SYMBOL_TO_STRING(ClassName));
Name | Type | Default | Description |
---|---|---|---|
importAlias | {String} |
BUILDTIME_SYMBOL_TO_STRING |
Macro name used to decorate symbols |