为什么未选择__webpack_public_path __

时间:2018-10-03 20:59:45

标签: reactjs webpack create-react-app chunking

因此,我正在使用CRA [create-react-app],并且不想弹出。我目前正在分块,或者正在使用react-loadable库毫无问题地创建块。

现在,我想从其他服务器加载块,因为主javascript文件将位于与Web服务器不同的位置。因此,在对块进行请求时,必须从“ http://my-static-server.com”加载它们。默认情况下,从主程序所在的目录中加载块。

我到处搜索,找到了一些解决方案,但是它们对我不起作用。这是有关操作方法的官方文档:

https://webpack.js.org/guides/public-path/#on-the-fly

我也在这里看过

https://github.com/webpack/webpack/issues/7077

这对我也不起作用。

不想弹出,我要寻求内联解决方案:

__webpack_public_path__ = process.env.ASSET_PATH;

认为在入口点就足够了吧?

我的代码:

import './src/containers/async/build';
import React from 'react'
import {render} from 'react-dom'
import {Provider} from 'react-redux'
import store from './store'
import App from './containers/app'

import './index.css'

const target = document.querySelector('#root');

render(
    <Provider store={store}>
        <React.Fragment>
            <App/>
        </React.Fragment>
    </Provider>,
    target
);

以及./src/containers/async/build中的

__webpack_public_path__ = 'http://example-server.com';

这不会失败,但是如果我运行构建:

yarn run build

我明白了

191.8 KB   build/static/js/ComponentOne.0c0b549a.chunk.js
154.06 KB  build/static/js/main.6d7817fb.js
25.03 KB   build/static/js/ComponentTwo.d2e1b30c.chunk.js
[...]
7.09 KB    build/static/css/main.fbb5d863.css

并检查build/static/js/main.6d7817fb.jshttp://example-server.com完全没有踪迹。我仍然得到类似的东西:

s.src=t.p+"static/js/"+({0:"ComponentOne",1:"ComponentTwo",2:"ComponentThree",3:"ComponentFour",4:"ComponentFive"}

我正在尝试从一开始就导入,以避免像此处指出的那样发生起吊之类的问题:

https://github.com/webpack/webpack/issues/2776

关于如何实现不弹出的任何想法?

0 个答案:

没有答案
相关问题