zoukankan      html  css  js  c++  java
  • webpack 开发环境配置

    webpack.config.js

    const { resolve } = require('path');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = {
      entry: './src/js/index.js',
      output: {
        filename: 'js/bundle.js',
        path: resolve(__dirname, 'build')
      },
      module: {
        rules: [
          // loader的配置
          {
            // 处理less资源
            test: /.less$/,
            use: ['style-loader', 'css-loader', 'less-loader']
          },
          {
            // 处理css资源
            test: /.css$/,
            use: ['style-loader', 'css-loader']
          },
          {
            // 处理图片资源
            test: /.(jpg|png|gif)$/,
            loader: 'url-loader',
            options: {
              limit: 8 * 1024,
              name: '[hash:10].[ext]',
              outputPath: 'imgs'
            }
          },
          {
            // 处理html中img资源
            test: /.html$/,
            loader: 'html-loader'
          },
          {
            // 处理其他资源
            exclude: /.(html|js|css|less|jpg|png|gif)/,
            loader: 'file-loader',
            options: {
              name: '[hash:10].[ext]',
              outputPath: 'media'
            }
          }
        ]
      },
      plugins: [
        // plugins的配置
        new HtmlWebpackPlugin({
          template: './src/index.html'
        })
      ],
      mode: 'development',
      devServer: {
        contentBase: resolve(__dirname, 'build'),
        compress: true,
        port: 3000,
        open: true
      }
    };

    运行指令:

    npx webpack : 会将打包结果输出出去

    npx webpack-dev-server 只会在内存中编译打包,没有输出

  • 相关阅读:
    2、ansilbe常用模块详解及inventory介绍
    1、Ansible简介及简单安装、使用
    dhcp、tftp及pxe简介
    php-fpm常见错误
    php之编译安装
    nginx之常见错误
    ssh之秘钥登陆
    MySQL之主从复制
    Python之虚拟环境
    php调试工具之firePHP
  • 原文地址:https://www.cnblogs.com/shanlu0000/p/13047209.html
Copyright © 2011-2022 走看看