-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the
noRuntime
option (#831)
- Loading branch information
Showing
6 changed files
with
208 additions
and
8 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
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,55 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`noRuntime option should work when noRuntime option is "false": DOM 1`] = ` | ||
"<!DOCTYPE html><html><head> | ||
<title>style-loader test</title> | ||
<style id=\\"existing-style\\">.existing { color: yellow }</style> | ||
<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"simple.css\\"><script charset=\\"utf-8\\" src=\\"simple.bundle.js\\"></script></head> | ||
<body> | ||
<h1>Body</h1> | ||
<div class=\\"target\\"></div> | ||
<iframe class=\\"iframeTarget\\"></iframe> | ||
</body></html>" | ||
`; | ||
exports[`noRuntime option should work when noRuntime option is "false": errors 1`] = `Array []`; | ||
exports[`noRuntime option should work when noRuntime option is "false": warnings 1`] = `Array []`; | ||
exports[`noRuntime option should work when noRuntime option is "true": DOM 1`] = ` | ||
"<!DOCTYPE html><html><head> | ||
<title>style-loader test</title> | ||
<style id=\\"existing-style\\">.existing { color: yellow }</style> | ||
<script charset=\\"utf-8\\" src=\\"simple.bundle.js\\"></script></head> | ||
<body> | ||
<h1>Body</h1> | ||
<div class=\\"target\\"></div> | ||
<iframe class=\\"iframeTarget\\"></iframe> | ||
</body></html>" | ||
`; | ||
exports[`noRuntime option should work when noRuntime option is "true": errors 1`] = `Array []`; | ||
exports[`noRuntime option should work when noRuntime option is "true": warnings 1`] = `Array []`; | ||
exports[`noRuntime option should work without noRuntime option: DOM 1`] = ` | ||
"<!DOCTYPE html><html><head> | ||
<title>style-loader test</title> | ||
<style id=\\"existing-style\\">.existing { color: yellow }</style> | ||
<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"simple.css\\"><script charset=\\"utf-8\\" src=\\"simple.bundle.js\\"></script></head> | ||
<body> | ||
<h1>Body</h1> | ||
<div class=\\"target\\"></div> | ||
<iframe class=\\"iframeTarget\\"></iframe> | ||
</body></html>" | ||
`; | ||
exports[`noRuntime option should work without noRuntime option: errors 1`] = `Array []`; | ||
exports[`noRuntime option should work without noRuntime option: warnings 1`] = `Array []`; |
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,105 @@ | ||
/* eslint-env browser */ | ||
import path from "path"; | ||
|
||
import MiniCssExtractPlugin from "../src/cjs"; | ||
|
||
import { | ||
compile, | ||
getCompiler, | ||
getErrors, | ||
getWarnings, | ||
runInJsDom, | ||
} from "./helpers/index"; | ||
|
||
describe("noRuntime option", () => { | ||
it(`should work without noRuntime option`, async () => { | ||
const compiler = getCompiler( | ||
"attributes.js", | ||
{}, | ||
{ | ||
output: { | ||
publicPath: "", | ||
path: path.resolve(__dirname, "../outputs"), | ||
filename: "[name].bundle.js", | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom, bundle) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
expect(bundle).toContain("webpack/runtime/css loading"); | ||
expect(bundle).toContain("webpack/runtime/get mini-css chunk filename"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it(`should work when noRuntime option is "false"`, async () => { | ||
const compiler = getCompiler( | ||
"attributes.js", | ||
{}, | ||
{ | ||
output: { | ||
publicPath: "", | ||
path: path.resolve(__dirname, "../outputs"), | ||
filename: "[name].bundle.js", | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
noRuntime: false, | ||
filename: "[name].css", | ||
}), | ||
], | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom, bundle) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
expect(bundle).toContain("webpack/runtime/css loading"); | ||
expect(bundle).toContain("webpack/runtime/get mini-css chunk filename"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it(`should work when noRuntime option is "true"`, async () => { | ||
const compiler = getCompiler( | ||
"attributes.js", | ||
{}, | ||
{ | ||
output: { | ||
publicPath: "", | ||
path: path.resolve(__dirname, "../outputs"), | ||
filename: "[name].bundle.js", | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
noRuntime: true, | ||
filename: "[name].css", | ||
}), | ||
], | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom, bundle) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
expect(bundle).not.toContain("webpack/runtime/css loading"); | ||
expect(bundle).not.toContain( | ||
"webpack/runtime/get mini-css chunk filename" | ||
); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
}); |