webpack public path 坑,记录

在业务中 使用 public path 时 需要 当做一个文件来import,不然会造成 css里面的图片先编译完,没有识别到这个cdn 变量
webpack public path 坑,记录-王树东的博客
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}/`;
喜欢()
评论 (0)
    热门搜索
    Top