
前端开发的时候,webpack devServer 转发的 api 会因为过不了这些保护检查而被拦下。不知道各位有没有比较优雅的方案?
我们现在是手动的把 cookie 复制在 localhost 域名下。
]]>import './some-dev-code.ts'some-dev-code.ts,加入判断 process.env.dev 然后抛错, 但是只能在 runtime 才知道... ]]>本地 IP: 198.0.1.2 防火墙已经关闭
然后用 webpack-dev-server 启动后,端口是 8080. 本地访问: http://locahost:8080/可以成功
另外一台机器 198.0.1.10 访问 http://198.0.1.2:8080 提示我
This site can’t be reached 198.0.1.2 refused to connect. 我添加了启动参数,比如:--public 0.0.0.0:8080 (或者 --public 198.0.1.2:8080 )看命令行,提示 server 启动成功,但是在浏览器里面输入 http://0.0.0.0:8080 直接提示我错误(就更别提远程访问了)
This site can’t be reached The webpage at http://0.0.0.0:8080/ might be temporarily down or it may have moved permanently to a new web address. google 了一下,什么 allowedHosts ,disableHostCheck 参数也设置了,貌似没有啥用。
p.s. refer to:
https://github.com/webpack/webpack-dev-server/issues/882
async function getLastCommitHash() { return new Promise(resolve => { require('child_process').exec('git rev-parse HEAD', function(err, stdout) { resolve(stdout); }); } } const run = async () => { const commit = await getLastCommitHash(); return { ... plugins: new webpack.DefinePlugin({ "process.env": commit }) } } 我参考了一下这里的做法: https://stackoverflow.com/questions/53991856/how-do-i-await-a-piece-of-code-within-weback-config
module.exports = run(); 或者
module.exports = run; 貌似都不行。
这,有没有办法,在 webpack.config.js 里面,先执行一段异步代码再返回配置呢?
]]>当我配置了 splitChunks, chunks: all, minChunks:2 的情况下 dep.js 并没有被单独提取出来
如果 A.js 没有引入依赖 dep.js 编译后 dep.js 就能被单独提取出来,这是为啥
]]>是 webpack 打包时,把 process.env 生成了一个文件,然后在 runtime 再把这些 variables 从文件里面读取出来了么?
我 google 了一下,找相关文档,没有找到。
]]>读到一篇文章,提到了,webpack 如果想在引入一个包的时候,编译只引入的那部分代码,需要 babel 的支持。而且,只对自己的代码有效。如果是第三方的包,还不行,得写一个插件,实现转换。比如,
import { x } from 'module1'; 转换成 import { x } from 'module1/a/bc'; 要这么麻烦才能够实现 tree-shaking 啊!
当然这是 3 年前的文章了,现在的 webpack 也进化到了 5.0 的版本了吧?现在还是这样的么?
]]>(()=>{"use strict";console.log("hello")})(); ]]>import('xxx'),但是这样 xxx 被限定住了,所谓动态,其实也是有指定范围的动态
你真的理解 Webpack ? 如果知道以下问题的答案,则意味着已经掌握了
Webpack。 欢迎提供您的答案。
Loader 和 Plugin 的不同Loader?他们能解决什么问题?Plugin?他们能解决什么问题?Webpack 来优化前端性能Webpack 的构建速度?bundle 体积进行监控和分析?Vue 和 React 项目中实现按需加载?monorepo 这种项目有什么好处,具体是如何打包的?Source Map 是什么?生产环境怎么用?Webpack 中如何做到长缓存优化?Webpack 中 hash chunkhash contenthash 有什么区别?Webpack 的构建流程是什么?Loader ?描述一下编写 Loader 的思路?Plugin ?描述一下编写 Plugin 的思路?inline pre post normal loader 执行先后顺序是?Webpack 打包的原理是什么?聊一聊 babel 和抽象语法树dev-server 的原理是什么?描述一下它的具体流程DIlPlugin 和 DllReferencePlugin 的工作原理Webpack 的热更新是如何做到的?说明其原理?Tree shaking了解过么?它的实现原理说一下Webpack 5 中有哪些新特性Webpack 5 中的 Module Federation 对微前端的意义define([ config, // ./config.js JApp, // ./modules/module-common/app.js ], function(config, JApp) { ... }); 同时,我还有个 config 文件:
define([], function() { return { config: 'config', JApp: './modules/module-common/app', HApp: './modules/module-common/app.html', }; }); 我在尝试使用 webpack 打包 main.js 时,webpack 会提示找不到模块‘JApp’,因为确实不存在嘛。 于是我就配置了一下 webpack.resolve.alias,就是直接将 config 文件的内容赋给 webpack.resolve.alias 。 但结果是仍旧报错:
Module not found: Error: Can't resolve 'JApp' in 'D:\codes\webpack\webpack-test\webapp\static' @ ../webapp/static/main.js 13:4-227:6
我该怎么解决这个问题呢?
]]>手段:新模块单独起个工程,采用 vue 开发。在老系统新增一个菜单 /目录,新模块编译好将文件放置老系统对应目录,然后老系统向以前一样随后端一期打包部署。
问题:如何打包 vue 工程,编译好又如何嵌入老系统?
否定方案:新系统单独部署一套环境,然后用 frame 弄个窗口。这种方案被否定了,因为需要新部署环境!
]]>webpack-dev-serer 调试的时候,bundle.css 里面某个资源路径是 url(../dist/images/wave.svg),但是等我 npm run build 构建出来的 bundle.css 里面资源路径却变成了 url(../../dist/images/wave.svg),百思不得其解啊。。。 项目及 webpack.config.js 在这里( Github )。

想学习 webpack 工程化和 vue 单文件组件开发的新手可以看看
来源:
内容:
先执行 npm run dist 生成了 dist 文件夹,
然后想通过 npm run dev 查看 example 中的效果,
结果 css 死活找不到,index.html 中的 css 指向自己修改过,
应该是和 webpack-dev-server 的配置有关的吧?
前端小菜前来请大佬们帮我指导一下。 不胜感激。

引申问题,如果是 webpack-dev-server 里的 js 因为是在内存中是不是更无法 debug 打断点了?
问题二 firefox 升级到 53 后,redux-devtools-extension 无法调出是不是普遍现象?根本找不到那个轮回眼的 icon 了,是不是因为开启了 firefox 的智能搜索提示呢?
谢谢大家
]]>结构如下
怎么能在 main.scss import 相对路径 的 scss 文件?
@import 'font-awesome/font-awesome.scss'; 一旦写进去, webpack devserver 就开始报错了, 只有放到 index.js 里 import 才行
没有解决办法
webpack 配置:
const path = require('path'); const webpack = require('webpack'); module.exports = { devtool: 'cheap-module-eval-source-map', entry: [ 'eventsource-polyfill', // necessary for hot reloading with IE 'webpack-hot-middleware/client', './src/index' ], output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/static/' }, plugins: [ /** * This is where the magic happens! You need this to enable Hot Module Replacement! */ new webpack.HotModuleReplacementPlugin(), /** * NoErrorsPlugin prevents your webpack CLI from exiting with an error code if * there are errors during compiling - essentially, assets that include errors * will not be emitted. If you want your webpack to 'fail', you need to check out * the bail option. */ new webpack.NoErrorsPlugin(), /** * DefinePlugin allows us to define free variables, in any webpack build, you can * use it to create separate builds with debug logging or adding global constants! * Here, we use it to specify a development build. */ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('development') }), ], module: { loaders: [ { test: /\.js?/, exclude: [/node_modules/, /styles/], loaders: ['babel'], include: path.join(__dirname, 'src') }, { test: /\.scss$/, loader: 'style!css!sass' }, { test: /\.css$/, loader: "style-loader!css-loader" }, { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' }, { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' } ] } }; 我只懂基本的webpack配置, 尝试了下改 entry 和output 都没啥用。。。
]]>现在有个困惑,怎样调试 webpack 打包好的代码? webpack 打包好的 bundle.js ,一脸茫然,根本看不懂,更加不用说调试。
不知大神有没有比较好的建议。指点指点一下小弟
]]>我的 webpack 配置
var webpack = require("webpack"); var ExtractTextPlugin = require("extract-text-webpack-plugin"); module.exports = { entry: { app: "./entry.js", vendor: ['bootstrap'], }, output: { path: __dirname + "/dist", filename: "bundle.js" }, module: { loaders: [ { test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")}, { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }, { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }, ] }, plugins: [ new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js"), new ExtractTextPlugin("[name].bundle.css", {allChunks: false}), ] }; 能生成 vendor.bundle.js 文件,且文件内容包含 bootstrap . 但没有生成 vendor.bundle.css 文件. 是 extract-text-webpack-plugin 不支持吗?
想到一种比较笨的办法,就是再建一个 css_entry.js 文件, 在文件里面调用 require('./node_modules/bootstrap/less/bootstrap.less') ,但感觉这个办法有点搓...
有什么更好解决方案的朋友吗?
]]>问题 1 : webpack 既然和 browserify 是一个类型的,当然,强大了许多,居然可以把 css 也当做了 compile to js 来使用。 gulp 也有很多插件完成 coffee script 或者 es6 到 js 的过程。为何这个轮子造出来了。难道是为了统一 AMD 和 commonjs 不同 module loading 问题?
问题 2 : learning curve 有点陡啊,不像 gulp 一上午就知道怎么用了。 小项目使用是不是有点过?
愚见,喷吧,反正也是学习。
]]>