1.0.3 • Published 5 years ago

expose-webpack-module v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

expose-webpack-module

An expose function implemented by AST (Syntax Abstract Tree) that modifies the webpack production code to return its running results.

image

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 !!!

After reading the html-webpack-plugin source code, I learned to use LibraryTemplatePlugin to solve this problem

// webpack.config.js
plugins: [
	new LibraryTemplatePlugin('HTML_WEBPACK_PLUGIN_RESULT', 'var'),
    new InjectPlugin({
        inject: source => source.replace('var HTML_WEBPACK_PLUGIN_RESULT =', '')
    })
]