欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

webpack资源加载常用配置

程序员文章站 2023-08-30 13:22:13
const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, mo... ......
const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {

      rules:[
              //   css加载
    //包下载命令:npm install --save-dev style-loader css-loader
          {
          test:/\.css$/,
          use:[
              'style-loader',
              'css-loader',
          ]
      },
          //   图片加载及字体加载
    //包下载命令:npm install --save-dev file-loader
      {
          test:/\.(png|jpg|gif)$/,
          use:[
              'file-loader'
          ]
      },
      {
          test:/\.(woff|woff2|eot|ttf|otf)$/,
          use:[
              'file-loader'
          ]
      },
    //   数据加载 (json是内置的,所以无需下载对应的包)
    //包命令:npm install --save-dev csv-loader xml-loader
      {
        test:/\.xml$/,
        use:[
            'xml-loader'
        ]
    },
    {
        test:/\.(csv|tsv)$/,
        use:[
            'csv-loader'
        ]
    }
    ]
  }
};