javascript - webpack dev server 不是会在内存中生成 bundle.js 吗?
怪我咯
怪我咯 2017-04-11 10:56:42
[JavaScript讨论组]

文件结构如下:

Project
 |
 +-- src/
 |   |
 |   +-- index.js
 |
 +-- index.html
 |
 +-- webpack.config.js

src/index.js:

 


    
    webpack learning

    




webpack.config.js:

var path = require('path');

module.exports = {
  entry: './src',
  output: {
    path: path.join(__dirname, 'builds'),
    filename: 'bundle.js',
  }
};

当我在项目目录运行 webpack-dev-server 时,webpack-dev-server 正常启动并输出:’webpack: bundle is now VALID'。然而,当我打开浏览器,并访问localhost:8080 时,控制台报错:

确实,没有生成builds/bundle.js。可是,我记得webpack-dev-server 是在内存里生成bundle.js 的,不会写到硬盘上,不知道为什么会报这个错。是我的webpack的配置问题吗?

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
高洛峰

When I add output.publicPath and set it to "builds", everything works just fine. It seems that when webpack-dev-server is generating bundle.js in memory, it puts that file in the directory specified by output.publicPath and ignores what directory the "output.path" is set to. Because whatever output.path is set to, as long as output.publicPath remains "builds", no error appears in the console and the browser renders "Hello World."

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号