-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: in dev mode imports SCSS in JS when in the same file is inlined …
…another SCSS file via `?inline`, #102
- Loading branch information
Showing
22 changed files
with
305 additions
and
4 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
5 changes: 5 additions & 0 deletions
5
test/cases/js-import-scss-and-inline-scss-dev/expected/index.css
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,5 @@ | ||
.import1 { | ||
color: red; | ||
}.import2 { | ||
color: green; | ||
} |
16 changes: 16 additions & 0 deletions
16
test/cases/js-import-scss-and-inline-scss-dev/expected/index.html
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,16 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
<link href="index.css" rel="stylesheet"> | ||
<style>.import3 { | ||
color: blue; | ||
}</style> | ||
</head> | ||
<body> | ||
<p class="import1">This text should be red (import1.scss)</p> | ||
<p class="import2">This text should be green (import2.scss)</p> | ||
<p class="import3">This text should be blue (import3.scss)</p> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
131 changes: 131 additions & 0 deletions
131
test/cases/js-import-scss-and-inline-scss-dev/expected/index.js
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,131 @@ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ var __webpack_modules__ = ({ | ||
|
||
/***/ "./src/import1.scss": | ||
/*!**************************!*\ | ||
!*** ./src/import1.scss ***! | ||
\**************************/ | ||
/***/ (() => { | ||
|
||
/* extracted by HTMLBundler CSSLoader */ | ||
|
||
/***/ }), | ||
|
||
/***/ "./src/import2.scss": | ||
/*!**************************!*\ | ||
!*** ./src/import2.scss ***! | ||
\**************************/ | ||
/***/ (() => { | ||
|
||
/* extracted by HTMLBundler CSSLoader */ | ||
|
||
/***/ }), | ||
|
||
/***/ "./src/import3.scss?inline": | ||
/*!*********************************!*\ | ||
!*** ./src/import3.scss?inline ***! | ||
\*********************************/ | ||
/***/ (() => { | ||
|
||
/* extracted by HTMLBundler CSSLoader */ | ||
|
||
/***/ }) | ||
|
||
/******/ }); | ||
/************************************************************************/ | ||
/******/ // The module cache | ||
/******/ var __webpack_module_cache__ = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ var cachedModule = __webpack_module_cache__[moduleId]; | ||
/******/ if (cachedModule !== undefined) { | ||
/******/ return cachedModule.exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/compat get default export */ | ||
/******/ (() => { | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = (module) => { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ () => (module['default']) : | ||
/******/ () => (module); | ||
/******/ __webpack_require__.d(getter, { a: getter }); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be in strict mode. | ||
(() => { | ||
"use strict"; | ||
/*!**********************!*\ | ||
!*** ./src/index.js ***! | ||
\**********************/ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var _import1_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./import1.scss */ "./src/import1.scss"); | ||
/* harmony import */ var _import1_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_import1_scss__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _import2_scss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./import2.scss */ "./src/import2.scss"); | ||
/* harmony import */ var _import2_scss__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_import2_scss__WEBPACK_IMPORTED_MODULE_1__); | ||
/* harmony import */ var _import3_scss_inline__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./import3.scss?inline */ "./src/import3.scss?inline"); | ||
/* harmony import */ var _import3_scss_inline__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_import3_scss_inline__WEBPACK_IMPORTED_MODULE_2__); | ||
// These two imports are not included in the bundled css when running `webpack --mode development`. | ||
// However, they are included in the bundled css when running `webpack --mode production`. | ||
|
||
|
||
|
||
// This css is always properly inlined in the HTML file. | ||
// Interestingly, if you comment this line out, then it fixes the issue with thea above imports | ||
// (they will be properly included in the bundled css in development mode). | ||
|
||
|
||
console.log("Hello World!"); | ||
|
||
})(); | ||
|
||
/******/ })() | ||
; |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-dev/src/import1.scss
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,3 @@ | ||
.import1 { | ||
color: red; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-dev/src/import2.scss
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,3 @@ | ||
.import2 { | ||
color: green; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-dev/src/import3.scss
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,3 @@ | ||
.import3 { | ||
color: blue; | ||
} |
12 changes: 12 additions & 0 deletions
12
test/cases/js-import-scss-and-inline-scss-dev/src/index.html
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,12 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<p class="import1">This text should be red (import1.scss)</p> | ||
<p class="import2">This text should be green (import2.scss)</p> | ||
<p class="import3">This text should be blue (import3.scss)</p> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
test/cases/js-import-scss-and-inline-scss-dev/src/index.js
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,11 @@ | ||
// These two imports are not included in the bundled css when running `webpack --mode development`. | ||
// However, they are included in the bundled css when running `webpack --mode production`. | ||
import "./import1.scss"; | ||
import "./import2.scss"; | ||
|
||
// This css is always properly inlined in the HTML file. | ||
// Interestingly, if you comment this line out, then it fixes the issue with thea above imports | ||
// (they will be properly included in the bundled css in development mode). | ||
import "./import3.scss?inline"; | ||
|
||
console.log("Hello World!"); |
31 changes: 31 additions & 0 deletions
31
test/cases/js-import-scss-and-inline-scss-dev/webpack.config.js
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,31 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
|
||
module.exports = { | ||
// test importing SCSS in JS in dev mode (in prod mode is OK) when in the same file is another SCSS file inlined via `?inline` query, #102 | ||
mode: 'development', | ||
|
||
output: { | ||
path: path.join(__dirname, 'dist/'), | ||
clean: true, | ||
publicPath: '', | ||
}, | ||
|
||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
entry: { | ||
index: './src/index.html', | ||
}, | ||
verbose: true, | ||
}), | ||
], | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(s?css)$/, | ||
use: ['css-loader', 'sass-loader'], | ||
}, | ||
], | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
test/cases/js-import-scss-and-inline-scss-prod/expected/index.css
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 @@ | ||
.import1{color:red}.import2{color:green} |
14 changes: 14 additions & 0 deletions
14
test/cases/js-import-scss-and-inline-scss-prod/expected/index.html
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 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
<link href="index.css" rel="stylesheet"> | ||
<style>.import3{color:blue}</style> | ||
</head> | ||
<body> | ||
<p class="import1">This text should be red (import1.scss)</p> | ||
<p class="import2">This text should be green (import2.scss)</p> | ||
<p class="import3">This text should be blue (import3.scss)</p> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
test/cases/js-import-scss-and-inline-scss-prod/expected/index.js
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 @@ | ||
(()=>{"use strict";console.log("Hello World!")})(); |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-prod/src/import1.scss
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,3 @@ | ||
.import1 { | ||
color: red; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-prod/src/import2.scss
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,3 @@ | ||
.import2 { | ||
color: green; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/cases/js-import-scss-and-inline-scss-prod/src/import3.scss
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,3 @@ | ||
.import3 { | ||
color: blue; | ||
} |
12 changes: 12 additions & 0 deletions
12
test/cases/js-import-scss-and-inline-scss-prod/src/index.html
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,12 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<p class="import1">This text should be red (import1.scss)</p> | ||
<p class="import2">This text should be green (import2.scss)</p> | ||
<p class="import3">This text should be blue (import3.scss)</p> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
test/cases/js-import-scss-and-inline-scss-prod/src/index.js
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,11 @@ | ||
// These two imports are not included in the bundled css when running `webpack --mode development`. | ||
// However, they are included in the bundled css when running `webpack --mode production`. | ||
import "./import1.scss"; | ||
import "./import2.scss"; | ||
|
||
// This css is always properly inlined in the HTML file. | ||
// Interestingly, if you comment this line out, then it fixes the issue with thea above imports | ||
// (they will be properly included in the bundled css in development mode). | ||
import "./import3.scss?inline"; | ||
|
||
console.log("Hello World!"); |
30 changes: 30 additions & 0 deletions
30
test/cases/js-import-scss-and-inline-scss-prod/webpack.config.js
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,30 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
|
||
output: { | ||
path: path.join(__dirname, 'dist/'), | ||
clean: true, | ||
publicPath: '', | ||
}, | ||
|
||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
entry: { | ||
index: './src/index.html', | ||
}, | ||
verbose: true, | ||
}), | ||
], | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(s?css)$/, | ||
use: ['css-loader', 'sass-loader'], | ||
}, | ||
], | ||
}, | ||
}; |
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