Git Product home page Git Product logo

webpack-demo's Introduction

问题记录

webpack-dev-server 可以启动并编译, 修改文件内容后 浏览器却无法自动刷新

复现步骤

  1. 克隆代码
  1. 进入问题代码所在目录
cd /webpack-demo/
  1. 安装依赖 并 启动热更新
  npm i

  npm run dev
  1. 修改资源文件 浏览器没有刷新 (问题点)

解决方案

  • 原因:webpack5 需要补充 target: 'web' 配置
module.exports = {
  mode: 'none',
  entry: './src/main.js',
  devtool: 'eval-cheap-module-source-map',
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist'),
  },
  target: 'web', // **
}

使用 动态导入后,打包结果没有对 动态导入的资源 进行分包

复现步骤

  1. 代码中使用了动态导入

src/main.js

import(
  /* webpackChunkName:'editor' */
  './editor/editor'
).then(({ default: createEditor }) => {
  const editor = createEditor()
  document.body.append(editor)
})
  1. 安装依赖后执行 打包命令
npm run build:default:none

webpack.config.js

  1. 预期结果

dist 目录下有以下 2 个文件

main-xxxxxx.bundle.js
editor-xxxxxx.bundle.js
  1. 实际结果

只有 main-xxxxxx.bundle.js

webpack-demo's People

Contributors

baboon-king avatar

Watchers

 avatar

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.