-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
- Remove unused path variable - Remove css manual entry point - Remove unused HMR optional rule since this feature does not work in MiniCssExtractPlugin - Clear out IgnoreEmitPlugin values
Add additional generated files from glob entries to ignore.
- Create a new entry object and and conditionally add style or editor entry points. - Entry points can be .scss or .css - Update loader test to .scss or .css
This file is no longer needed with this update since the entry has been removed from webpack.config.js.
@michealengland Thank you for your work on this. Would you be willing to create a branch off of Then all of the reviewers could pull down that branch, run I know this is asking extra of you (and I very much appreciate all you have already done). I do think overall it would streamline the review process so reviewers aren't duplicating this work. |
This is a great idea, I'll get a test branch created and posted shortly. |
@salcode Here is a quick test branch I put together. example/conditional-css-imports-demo This branch demonstrates the following scenarios
Note: While creating this branch I learned that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, this looks good (and runs properly) for me too. 👍
Include Style & Editor Webpack Entries
Note: This is a temporary solution until Webpack 5 is release which we will resume using splitChunks as recommended by
mini-css-extract-plugin
.Special props shoutout to @salcode for helping simplify this PR dramatically.
This update is a workaround for extracting all CSS into a singular file based on entry name. The recommended method from
mini-css-extract-plugin
is to use splitChunks. However, this feature breaks the main entry JS file. According to this thread webpack-contrib/mini-css-extract-plugin#147 the feature is fixed for Webpack 5 and is not being worked on for Webpack 4 which is our current version. There is not an official release Webpack 5 at this time.Proposed Solution
Using
glob.sync()
we'll conditionally check the/src
directory for allstyle.scss
oreditor.scss
files and add to a glob which will be used as an entry point. If no files are located for eitherstyle.scss
oreditor.scss
then no entry points will be added.Example Directory Structure
📦src
┣ 📂directory-1
┃ ┣ 📜editor.scss
┃ ┣ 📜index.js
┃ ┗ 📜style.scss
┣ 📂directory-2
┃ ┣ 📜editor.scss
┃ ┣ 📜index.js
┃ ┗ 📜style.scss
┣ 📂directory-3
┃ ┣ 📂d3-nested
┃ ┃ ┣ 📜editor.scss
┃ ┃ ┗ 📜index.js
┃ ┣ 📜index.js
┃ ┗ 📜style.scss
┣ 📜index.js
┗ 📜readme.md
Once all of the files have been located the entry points will transcode into a singular
editor.css
andstyle.css
in the/build
directory. It's worth mentioning that additional files are generated and ignored with theEmit
plugin. See ignored files.Example Build Files
📦build
┣ 📜editor.css
┣ 📜index.js
┗ 📜style.css
Ignored Files
Additional Notes
glob.sync()
stylesheets or sass files with a name ofstyle
oreditor
will be auto-loaded if they're located in/src
directory. Each file will be transcoded into astyle.css
oreditor.css
based on the name. This could be an unwanted feature since it's common practice for styles to be imported in the JS.glob.sync()
is not as performant assplitChunks
.How to Test
npm run start
ornpm run build
will generate build files.style.scss
oreditor.scss
and verify that your assets are being generated as expected.If you have any questions or need help, I'm available.