Person = () => import('components/page/Person') 更换成 Person = require('components/page/Person').default 或者 import Person from 'components/page/Person';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
chainWebpack: config => {
// 打包所有文件内嵌到html里面
//把图片转成base64 limit:1e5 => 100000 kb ,小于这个大小都会转成base64,大于就会用链接引用图片
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, {esModule:false,limit: 1e5}));
//把字体图标相关文件转成base64
config.module.rule('fonts').use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, {limit: 1e5}));
//把svg转成base64
const svgRule = config.module.rule('svg');
svgRule.uses.clear();
svgRule.rule('svg').use('url-loader')
.loader('url-loader')
.tap(options => ({esModule:false,limit:1e5}));
config.plugin('inline-source').use(require('html-webpack-inline-source-plugin'));
config.plugin('html').tap(args => {
args[0].inlineSource = '(.css|.js$)';
return args;
});
}
plugins:[
new HtmlWebpackPlugin({
template: 'public/index.html',
inlineSource: '.(js|css)$'
}),
new HtmlWebpackInlineSourcePlugin()
);
]
报错:Cannot read property ‘getHooks’ of undefined
依赖版本
"webpack": "^4.46.0"
"html-webpack-plugin": "^4.5.2",
"html-webpack-inline-source-plugin": "^1.0.0-beta.1",
"@vue/cli-service": "~4.4.0",
解决方法
报错: Rule can only have one resource source (provided resource and test + include + exclude) in
依赖版本
"webpack": "^5.24.4"
"@vue/cli-service": "~4.4.0",
"html-webpack-inline-source-plugin": "^1.0.0-beta.1",
"html-webpack-plugin": "^5.3.1"
解决方法
报错
网上的方法不太好使,大多数都是升级webpack,然后卸载node_modules 、package-lock.json 然后重新npm install
版本不匹配造成的,于是降低插件版本