Skip to content

Commit

Permalink
fix: add style and css loader to sass/less/stylus replaces #3172 (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealSyler committed Sep 19, 2022
1 parent bfe09c7 commit 8581a4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');<% } %><% if (wo
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');<% } %>

const isProduction = process.env.NODE_ENV == 'production';
<% if (isCSS) { %>
<% if (cssType !== 'none') { %>
<% if (extractPlugin === "Yes") { %>
const stylesHandler = MiniCssExtractPlugin.loader;
<% } else if (extractPlugin === "Only for Production") { %>
Expand Down Expand Up @@ -56,11 +56,11 @@ const config = {
},<% } %><% if (cssType == 'LESS') { %>
{
test: /\.less$/i,
use: [<% if (isPostCSS) { %>stylesHandler, 'css-loader', 'postcss-loader', <% } %>'less-loader'],
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'less-loader'],
},<% } %><% if (cssType == 'Stylus') { %>
{
test: /\.styl$/i,
use: [<% if (isPostCSS) { %>stylesHandler, 'css-loader', 'postcss-loader', <% } %>'stylus-loader'],
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'stylus-loader'],
},<% } %><% if (isPostCSS && isCSS) { %>
{
test: /\.css$/i,
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/src/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export async function questions(
break;
}

if (isCSS) {
if (cssType !== "none") {
self.dependencies.push("style-loader", "css-loader");
}

Expand Down
24 changes: 22 additions & 2 deletions test/init/__snapshots__/init.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,10 @@ exports[`init command should use less in project when selected 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"css-loader": "x.x.x",
"less": "x.x.x",
"less-loader": "x.x.x",
"style-loader": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
},
Expand All @@ -731,6 +733,8 @@ const path = require(\\"path\\");

const isProduction = process.env.NODE_ENV == \\"production\\";

const stylesHandler = \\"style-loader\\";

const config = {
entry: \\"./src/index.js\\",
output: {
Expand All @@ -744,7 +748,7 @@ const config = {
rules: [
{
test: /\\\\.less$/i,
use: [\\"less-loader\\"],
use: [stylesHandler, \\"css-loader\\", \\"less-loader\\"],
},
{
test: /\\\\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
Expand Down Expand Up @@ -772,8 +776,10 @@ exports[`init command should use mini-css-extract-plugin when selected 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"css-loader": "x.x.x",
"sass": "x.x.x",
"sass-loader": "x.x.x",
"style-loader": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
},
Expand All @@ -795,6 +801,8 @@ const path = require(\\"path\\");

const isProduction = process.env.NODE_ENV == \\"production\\";

const stylesHandler = \\"style-loader\\";

const config = {
entry: \\"./src/index.js\\",
output: {
Expand Down Expand Up @@ -980,8 +988,10 @@ exports[`init command should use sass in project when selected 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"css-loader": "x.x.x",
"sass": "x.x.x",
"sass-loader": "x.x.x",
"style-loader": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
},
Expand All @@ -1003,6 +1013,8 @@ const path = require(\\"path\\");

const isProduction = process.env.NODE_ENV == \\"production\\";

const stylesHandler = \\"style-loader\\";

const config = {
entry: \\"./src/index.js\\",
output: {
Expand Down Expand Up @@ -1045,10 +1057,12 @@ Object {
"description": "My webpack project",
"devDependencies": Object {
"autoprefixer": "x.x.x",
"css-loader": "x.x.x",
"postcss": "x.x.x",
"postcss-loader": "x.x.x",
"sass": "x.x.x",
"sass-loader": "x.x.x",
"style-loader": "x.x.x",
"webpack": "x.x.x",
"webpack-cli": "x.x.x",
},
Expand All @@ -1070,6 +1084,8 @@ const path = require(\\"path\\");

const isProduction = process.env.NODE_ENV == \\"production\\";

const stylesHandler = \\"style-loader\\";

const config = {
entry: \\"./src/index.js\\",
output: {
Expand Down Expand Up @@ -1111,6 +1127,8 @@ exports[`init command should use stylus in project when selected 1`] = `
Object {
"description": "My webpack project",
"devDependencies": Object {
"css-loader": "x.x.x",
"style-loader": "x.x.x",
"stylus": "x.x.x",
"stylus-loader": "x.x.x",
"webpack": "x.x.x",
Expand All @@ -1134,6 +1152,8 @@ const path = require(\\"path\\");

const isProduction = process.env.NODE_ENV == \\"production\\";

const stylesHandler = \\"style-loader\\";

const config = {
entry: \\"./src/index.js\\",
output: {
Expand All @@ -1147,7 +1167,7 @@ const config = {
rules: [
{
test: /\\\\.styl$/i,
use: [\\"stylus-loader\\"],
use: [stylesHandler, \\"css-loader\\", \\"stylus-loader\\"],
},
{
test: /\\\\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
Expand Down

0 comments on commit 8581a4b

Please sign in to comment.