Code Monkey home page Code Monkey logo

webpack-tool's Introduction

webpack-tool

Koa Webpack Dev Server:

  • development mode, start webpack koa server, file memory, hot update.

  • production mode, webpack build file to disk.

Version

  • webpack 5: webpack-tool: 5.x.x
  • webpack 4: webpack-tool: 4.x.x
  • webpack 3: webpack-tool: 3.x.x

Install

$ npm i webpack-tool --save

Usage

//build/index.js
const WebpackTool = require('webpack-tool');
const NODE_ENV = process.env.VIEW;

const webpackTool = new WebpackTool({
  devServer: {
    before: before => {
      // register koa middleware
    },
    after: app => {
      // register koa middleware
    },
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        pathRewrite: {'^/api' : ''}
      }
    },
    historyApiFallback: {
      index: '/app.html'
    }
  }
});

const webpackConfig = {
  entry:{
    index: './src/index.js'
  },
  module:{
    rules:[]
  }
  plugins: []
};

if (NODE_ENV === 'development') {
  // start webpack build and show build result ui view
  webpackTool.server(webpackConfig);
} else {
  // if you want to show build result ui view for build mode, please set  process.env.BUILD_VIEW=true
  webpackTool.build(webpackConfig);
}

Configuration

config.devServer support follow option:

Run

"scripts": {
  "start": "cross-env node build"
 }
npm start

Start Webpack Debug Server: http://127.0.0.1:8888/debug

UI-VIEW

webpack-tool's People

Contributors

hubcarl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

webpack-tool's Issues

在 webpack 5 出来前更新下 webpack 4 版本?

项目 package.json 中 webpack 版本为 4.42.1。
但是 webpack-tool 的 package.json 中 webpack 版本设定为 4.28.4。
然后使用 HotModuleReplacementPlugin 时,保存代码触发再次构建,会出现以下报错:

nodejs.TypeError: compilation.getPathWithInfo is not a function

希望能升级下 webpack 4 版本,谢谢。

devServer中historyApiFallback配置rewrites规则,相关依赖包报错

webpack-tool版本4.4.2

场景: 一个多入口的纯前端项目, 需要针对入口配置对应的historyApiFallback规则

重现步骤和问题: devServer中historyApiFallback配置rewrites规则, 访问对应rewrite规则命中的地址, 脚本报错: 'req is not defined' , 对应报错的依赖包是koa-history-api-fallback, 报错位置line84:
logger('Rewriting', req.method, req.url, 'to', rewriteTarget);

koa-history-api-fallback的git仓库中最新代码已修复该问题, 但npm包代码是旧的, 是否可以更新webpack-tool去依赖koa-history-api-fallback的git仓库, 或者有什么别的解决办法

不支持watch选项

在 webpack.config.js 中指定watch : true 后, 脚本报错, 手动修改 lib/tools.js #102 行, 将 compiler.plugin('done', ...) 注释掉后才可以

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.