首页
技术
生活
常用脚本
技术文档
关于
webpack public path 坑,记录
  • 作者:王树东
  • 发布于:2019-02-27 16:16:41
  • 更新于:2019-02-27 16:18:17
在业务中 使用 public path 时 需要 当做一个文件来import,不然会造成 css里面的图片先编译完,没有识别到这个cdn 变量 2019-02-27-16-18-03 https://webpack.js.org/guides/public-path/#use-cases
webpack_public_path = process.env.ASSET_PATH; That's all you need. Since we're already using the DefinePlugin on our configuration, process.env.ASSET_PATH will always be defined so we can safely do that. Be aware that if you use ES6 module imports in your entry file the webpack_public_path assignment will be done after the imports. In such cases, you'll have to move the public path assignment to its own dedicated module and then import it on top of your entry.js: // entry.js import './public-path'; import './app';

在业务中 使用 public path 时 需要 当做一个文件来import,不然会造成 css里面的图片先编译完,没有识别到这个cdn 变量

// entry.js import './public-path'; import './app';
public-path
// let publicPath = '/url';
// if (location.hostname.indexOf('dev') === 0 || location.hostname === 'localhost') {
//   // publicPath = 'dev' + publicPath;
//   publicPath = '';
// } else if (location.hostname.indexOf('qa') === 0) {
//   publicPath = '//url';
// } else if (location.hostname.indexOf('yz') === 0) {
//   publicPath = '//url';
// }
// if (window.isLocal) {
//   publicPath = ''
// }
// __webpack_public_path__ = `${publicPath}/`;

评论

暂无评论

发表评论

王树东的博客

Copyright © 2014-2020冀ICP备12011960号-15

FLOW ME

wsd312@163.com技术咨询和服务
starkland@163.combusiness cooperation

公众号

个人微信交个朋友
欢迎关注服务号更多技术等你来看