webpack配置

快来打我* 2022-05-11 09:30 283阅读 0赞

var path = require(‘path’);
var MiniTextPlugin = require(‘mini-css-extract-plugin’);
var uglifyjs = require(‘uglifyjs-webpack-plugin’);
var HtmlWebpackPlugin = require(‘html-webpack-plugin’);

module.exports = {
entry: ‘./src/main.js’,
output: {
filename: ‘bundle.js’,
path: path.resolve(__dirname, ‘dist’),
// publicPath: ‘http://localhost:8080’,
},
module: {
rules: [
{
test: /.lessKaTeX parse error: Expected ‘EOF’, got ‘}‘ at position 83: …’] }̲, {…/,
use: [‘style-loader’, ‘css-loader’]
},
// js loaders
{
test: /.jsKaTeX parse error: Expected ‘EOF’, got ‘}‘ at position 219: …s/ }̲, /…/,
use: [
{
loader: ‘file-loader’,
options: {
name: “[name].html”
}
},
{
loader: “extract-loader”
},
{
loader: “html-loader”,
options: {
attrs: [“img:src”]
}
}

  1. ]
  2. },
  3. // img-loader
  4. {
  5. test: /\.(jpg|png|gif)$/,
  6. use: [
  7. {
  8. loader: 'file-loader',
  9. options: {
  10. name: 'img/[name]-[hash:8].[ext]'
  11. }
  12. }
  13. ]
  14. }
  15. ]
  16. },
  17. plugins: [
  18. // 单独打包css
  19. new MiniTextPlugin({
  20. // 从.js文件中提取出来的.css文件名称
  21. filename: '[name]_[contenthash:8].css',
  22. // chunkFilename:'[id].css'
  23. }),
  24. // 压缩css
  25. new uglifyjs(),
  26. new HtmlWebpackPlugin({
  27. title: 'tittle',
  28. template: './src/demo.html',
  29. // minify: {
  30. // collapseWhitespace: true
  31. // },
  32. // hash: true
  33. })
  34. ],
  35. mode: 'development'

}

发表评论

表情:
评论列表 (有 0 条评论,283人围观)

还没有评论,来说两句吧...

相关阅读

    相关 webpack配置指南

    > Webpack已经出来很久了,相关的文章也有很多,然而比较完整的例子却不是很多,让很多新手不知如何下脚,下脚了又遍地坑 > > 说实话,官方文档是蛮乱的,而且有些还是错的

    相关 webpack配置

    1.新建文件夹 webpack-demo vscode 打开文件 -》打开控制台(只要进入文件目录中) 2.初始化webpack webpack init -