Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add crossOriginLoading option support #313

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add munual cases for crossOriginLoading option
  • Loading branch information
chikara-chan committed Nov 25, 2018
commit 1e33e2318094e0305c9f1bb8c61a2a0d69aa08dc
4 changes: 4 additions & 0 deletions test/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<p>Preloaded inlined CSS: Must be green.</p>
<p><button class="preloaded-button2">Pressing this button</button> displays an alert and should turn red.</p>
</div>
<div class="test crossorigin">
<p>CrossOriginLoading Option: Must be red.</p>
<p><button>Pressing this button</button> loads chunks with crossorigin attribute and should turn green.</p>
</div>
<div class="errors"></div>
<script async defer src="/dist/main.js"></script>
</body>
Expand Down
3 changes: 3 additions & 0 deletions test/manual/src/crossorigin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.crossorigin {
background: lightgreen;
}
1 change: 1 addition & 0 deletions test/manual/src/crossorigin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './crossorigin.css';
14 changes: 14 additions & 0 deletions test/manual/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1"
makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2'));

makeButton(".lazy-failure-button", () => import('./lazy-failure.js'), false);

makeButton(".crossorigin", () => {
const originalPublicPath = __webpack_public_path__;
__webpack_public_path__ = "http://0.0.0.0:8080/dist/";
const promise = import("./crossorigin").then(() => {
const lastTwoElements = Array.from(document.head.children).slice(-2);
const hasCrossorigin = lastTwoElements.every(element => element.crossOrigin === "anonymous");
if (!hasCrossorigin) {
throw new Error('Chunks miss crossorigin="anonymous" attribute.')
}
});
__webpack_public_path__ = originalPublicPath;
return promise;
});
4 changes: 4 additions & 0 deletions test/manual/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
output: {
chunkFilename: "[contenthash].js",
publicPath: '/dist/',
crossOriginLoading: 'anonymous',
},
module: {
rules: [
Expand All @@ -25,5 +26,8 @@ module.exports = {
],
devServer: {
contentBase: __dirname,
headers: {
"Access-Control-Allow-Origin": "*",
}
},
};