README
expose-webpack-module
An expose function implemented by AST (Syntax Abstract Tree) that modifies the webpack production code to return its running results.
install
npm i expose-webpack-module --save
example
./test/index.js
import expose from "expose-webpack-module"
const source = "some code like ./test/source.js"
const target = expose(source)
with inject-content-webpack-plugin
plugins: [
new InjectPlugin({
inject: expose
})
]
Last but not least !!!
html-webpack-plugin source code, I learned to use LibraryTemplatePlugin to solve this problem
After reading the// webpack.config.js
plugins: [
new LibraryTemplatePlugin('HTML_WEBPACK_PLUGIN_RESULT', 'var'),
new InjectPlugin({
inject: source => source.replace('var HTML_WEBPACK_PLUGIN_RESULT =', '')
})
]