手动用webpack-chain 搭建移动端react环境

本文档介绍了如何使用webpack-chain手动搭建一个移动端的React应用环境。内容包括项目介绍、webpack-chain的基本概念、详细的webpack配置步骤,如入口出口设置、postcss配置、html-webpack-plugin、其他plugin、服务器配置、别名、css/sass loader、文件loader、Babel支持React语法、eslint检查以及遇到的问题和解决方法。
摘要由CSDN通过智能技术生成

项目介绍

一个移动端web-app项目 基于webpack-chain(vue2.0的打包工具)

webpack-chain介绍

一个可以链式调用的webpack配置

webpack-config.js配置

const {
    merge } = require('webpack-merge')

const common = require('./config/common.js')
const dev = require('./config/dev')


module.exports = env => merge(common, dev)

通过webpack-merge合并生产模式和开发模式

配置入口出口

config
  // 修改 entry 配置
  .entry('index')
  .add(resolve('src/index.js'))
  .end()
  // 修改 output 配置
  .output
  .path(resolve('dist'))
  .filename('[name].bundle.js')
  .end()

移动端postcss.config.js设置

module.exports = {
   
    plugins: {
   
        // 'autoprefixer': {
   
        //     browsers: ['Android >= 4.0', 'iOS >= 7']
        // },
        'postcss-pxtorem': {
   
            rootValue: 37.5,
            unitPrecision: 3,
            propList: ['*'],
            exclude: '/node_modules'
        }
    }
}

配置html-webpack-plugin

const HtmlWebpackPlugin = require('html-webpack-plugin');

config.plugin('html')
  .use(HtmlWebpackPlugin, [
    {
   
      template: resolve('public/index.html'),
      filename: resolve('dist/index.html'),
      minify: true,
      inject: 'body',
      scriptLoading: 'blocking'
    }
  ])

配置其他plugin

new webpack.ProgressPlugin()
config.plugin('html')
  .use(HtmlWebpackPlugin, [
    {
   
      template: resolve('public/index.html'),
      filename: resolve('dist/index.html'),
      minify: true,
      inject: 'body'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值