1. 首页
  2. 代码碎片

webpack public path 坑,记录

在业务中 使用 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}/`;

原创文章,作者:stark,如若转载,请注明出处:https://shudong.wang/10285.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-800-8888

在线咨询:点击这里给我发消息

邮件:starkwang312@gmail.com

工作时间:周一至周五,9:30-18:30,节假日休息