PS E:\vscode\.vscode\mini-loader-plugin-demo-master> npm run build:mini
> mini-loader-plugin-demo@1.0.0 build:mini E:\vscode\.vscode\mini-loader-plugin-demo-master
> webpack --mode production --config ./build/webpack.config.mini.js
[12:43:22] [id 1] 0.17s Build finishError in file 4:1:1
Module build failed (from E:/vscode/.vscode/mini-loader-plugin-demo-master/node_modules/mini-program-webpack-loader/src/index.js):
TypeError: DomHandler is not a constructor
at parseDOM (E:\vscode\.vscode\mini-loader-plugin-demo-master\node_modules\mini-program-webpack-loader\src\helpers\html-mini-loader.js:10:19)
看了上面的报错找到报错的文件
const DomHandler = require('domhandler')
const { DomUtils, Parser } = require('htmlparser2')
const ElementType = require('domelementtype')
function trimWhitespace (str) {
return str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '')
}
function parseDOM (data, options) {
const handler = new DomHandler(options)
const parser = new Parser(handler, options)
...
第一行改成这样就好了
const DomHandler = require('domhandler').DomHandler
const { DomUtils, Parser } = require('htmlparser2')
const ElementType = require('domelementtype')
function trimWhitespace (str) {
return str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '')
}
function parseDOM (data, options) {
const handler = new DomHandler(options)
const parser = new Parser(handler, options)