如何解决Handlebars 内置 Helpers 日志不适用于 webpack?
我有一个带把手的 webpack 项目。我想使用内置助手 {{log "test"}} 但没有结果。使用 gulp,相同的代码在控制台中给出输出。我不明白这是怎么回事。其余的助手工作良好。问题仅在 {{log}} 中。 我的 webpack 配置不正确吗?
const
path = require( 'path' ),webpack = require( "webpack" ),HTMLWebpackPlugin = require( 'html-webpack-plugin' ),{CleanWebpackPlugin} = require( 'clean-webpack-plugin' ),MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ),CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' ),TerserPlugin = require( 'terser-webpack-plugin' )
const isDev = process.env.NODE_ENV === 'development'
const isProd = !isDev
module.exports = {
mode: 'development',context: path.resolve( __dirname,'src' ),entry: {
main: './main.js'
},output: {
filename: 'bundle.js',path: path.resolve( __dirname,'dist' )
},devServer: {
contentBase: path.join( __dirname,'dist' ),port: 3000,open: false,overlay: true,stats: 'errors-only',},resolve: {
extensions: ['.css','.scss','.js','.json'],alias: {
'@': path.resolve( __dirname,'src' )
}
},plugins: [
new webpack.ProvidePlugin( {
$: 'jquery',jQuery: 'jquery',} ),new HTMLWebpackPlugin( {
title: 'MF',filename: 'index.html',template: './index.hbs',templateParameters() {
const tariffs = require( './src/json/tariffs' )
const performance = require( './src/json/performance' )
const info = require( './src/json/info' )
const cities = require( './src/json/cities' )
const unite = require( './src/json/unite' )
return {tariffs,performance,info,cities,unite}
},minify: isProd,new MiniCssExtractPlugin( {
filename: 'style.css',new CleanWebpackPlugin(),],module: {
rules: [
{
test: /\.hbs$/,loader: "handlebars-loader",options: {
helperDirs: [
path.join( __dirname,'src','helpers' )
],partialDirs: [
path.join( __dirname,'components' ),path.join( __dirname,'components','modals' ),]
}
},{
test: /\.(sa|sc|c)ss$/,use: [MiniCssExtractPlugin.loader,'css-loader','postcss-loader','sass-loader'],{
test: /\.(woff|woff2)$/,loader: 'file-loader',options: {
name: '[path][name].[ext]',}
},{
test: /\.(png|jpg|gif|svg)$/,{
test: /\.m?js$/,exclude: /(node_modules|bower_components)/,use: {
loader: 'babel-loader',options: {
presets: ['@babel/preset-env']
}
}
}
]
},optimization: {
minimizer: [
new CssMinimizerPlugin(),// css
new TerserPlugin() // js
],}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。