是的,您可以使用该功能,但仍然需要对代码进行一些修改-onClick。
Webpack
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const {
CleanWebpackPlugin
} = require('clean-webpack-plugin');
module.exports = (env,argv) => {
return {
devtool: argv.mode === 'production' ? 'none' : 'source-map',mode: argv.mode === 'production' ? 'production' : 'development',entry: {
MYSCRIPT: './sources/script.js'
},output: {
path: path.resolve(__dirname,'./dist'),filename: './[name].js',library: '[name]',libraryTarget: 'var',},module: {
rules: [{
test: /\.js$/,exclude: /node_modules/,use: {
loader: 'babel-loader'
}
},]
},plugins: [
new CleanWebpackPlugin({
verbose: true
}),new HtmlWebPackPlugin({
filename: 'index.html',template: './sources/index.html'
})
]
}
}
最重要的部分是名称输入和输出。
您还必须导出每个函数。
JS
export function test(type) {
alert(type);
}
我们可以通过这种方式来使用该功能。
HTML
<a onClick="MYSCRIPT.test('bar')">click</a>
您可以找到整个设计示例here。
本文链接:https://www.f2er.com/3131509.html