-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error with contenthash and css experiment
- Loading branch information
Showing
7 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body { | ||
background: yellow; | ||
color: green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'async'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as style from "./style.css"; | ||
|
||
it("should work with js", done => { | ||
import('./async.js').then(x => { | ||
expect(x.name).toBe("async") | ||
done(); | ||
}, done); | ||
}); | ||
|
||
it("should work with css", done => { | ||
expect(style).toEqual(nsObj({})); | ||
|
||
const computedStyle = getComputedStyle(document.body); | ||
|
||
expect(computedStyle.getPropertyValue("background")).toBe(" green"); | ||
expect(computedStyle.getPropertyValue("color")).toBe(" yellow"); | ||
|
||
import("./async.css").then(x => { | ||
expect(x).toEqual(nsObj({})); | ||
|
||
const style = getComputedStyle(document.body); | ||
|
||
expect(style.getPropertyValue("background")).toBe(" yellow"); | ||
expect(style.getPropertyValue("color")).toBe(" green"); | ||
|
||
done(); | ||
}, done); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body { | ||
background: green; | ||
color: yellow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fs = require("fs"); | ||
|
||
let cssBundle; | ||
|
||
module.exports = { | ||
findBundle: function (_, options) { | ||
const jsBundleRegex = new RegExp(/^bundle\..+\.js$/, "i"); | ||
const cssBundleRegex = new RegExp(/^bundle\..+\.css$/, "i"); | ||
const asyncRegex = new RegExp(/^async\..+\.js$/, "i"); | ||
const files = fs.readdirSync(options.output.path); | ||
const jsBundle = files.find(file => jsBundleRegex.test(file)); | ||
|
||
if (!jsBundle) { | ||
throw new Error( | ||
`No file found with correct name (regex: ${ | ||
jsBundleRegex.source | ||
}, files: ${files.join(", ")})` | ||
); | ||
} | ||
|
||
const async = files.find(file => asyncRegex.test(file)); | ||
|
||
if (!async) { | ||
throw new Error( | ||
`No file found with correct name (regex: ${ | ||
asyncRegex.source | ||
}, files: ${files.join(", ")})` | ||
); | ||
} | ||
|
||
cssBundle = files.find(file => cssBundleRegex.test(file)); | ||
|
||
if (!cssBundle) { | ||
throw new Error( | ||
`No file found with correct name (regex: ${ | ||
cssBundleRegex.source | ||
}, files: ${files.join(", ")})` | ||
); | ||
} | ||
|
||
return [jsBundle, async]; | ||
}, | ||
moduleScope(scope) { | ||
const link = scope.window.document.createElement("link"); | ||
link.rel = "stylesheet"; | ||
link.href = cssBundle; | ||
scope.window.document.head.appendChild(link); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = { | ||
target: "web", | ||
mode: "development", | ||
output: { | ||
filename: "bundle.[name].[contenthash].js", | ||
cssFilename: "bundle.[name].[contenthash].css", | ||
chunkFilename: "async.[name].[contenthash].js", | ||
cssChunkFilename: "async.[name].[contenthash].css" | ||
}, | ||
experiments: { | ||
css: true | ||
} | ||
}; |