From 55b8502dd02574a719090a84c1e7cf89f827d28c Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 20 Jan 2021 00:25:46 -0500 Subject: [PATCH 01/42] chore: compile `style-loader` dep (#21355) This PR compiles `style-loader` to resolve a peer dep warning. --- Closes #21359 --- packages/next/build/webpack-config.ts | 1 + .../config/blocks/css/loaders/client.ts | 2 +- .../webpack/loaders/next-style-loader/LICENSE | 20 + .../loaders/next-style-loader/index.js | 345 ++++++++++++++++++ .../runtime/injectStylesIntoLinkTag.js | 75 ++++ .../runtime/injectStylesIntoStyleTag.js | 294 +++++++++++++++ .../runtime/isEqualLocals.js | 33 ++ packages/next/package.json | 1 - yarn.lock | 9 +- 9 files changed, 770 insertions(+), 10 deletions(-) create mode 100644 packages/next/build/webpack/loaders/next-style-loader/LICENSE create mode 100644 packages/next/build/webpack/loaders/next-style-loader/index.js create mode 100644 packages/next/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoLinkTag.js create mode 100644 packages/next/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoStyleTag.js create mode 100644 packages/next/build/webpack/loaders/next-style-loader/runtime/isEqualLocals.js diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 873a0d1cc20dc..2ea65df283328 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -875,6 +875,7 @@ export default async function getBaseWebpackConfig( 'next-serverless-loader', 'noop-loader', 'next-plugin-loader', + 'next-style-loader', ].reduce((alias, loader) => { // using multiple aliases to replace `resolveLoader.modules` alias[loader] = path.join(__dirname, 'webpack', 'loaders', loader) diff --git a/packages/next/build/webpack/config/blocks/css/loaders/client.ts b/packages/next/build/webpack/config/blocks/css/loaders/client.ts index f09e66c1f1d25..c8d5bdc0bfda5 100644 --- a/packages/next/build/webpack/config/blocks/css/loaders/client.ts +++ b/packages/next/build/webpack/config/blocks/css/loaders/client.ts @@ -10,7 +10,7 @@ export function getClientStyleLoader({ }): webpack.RuleSetUseItem { return isDevelopment ? { - loader: require.resolve('style-loader'), + loader: 'next-style-loader', options: { // By default, style-loader injects CSS into the bottom // of . This causes ordering problems between dev diff --git a/packages/next/build/webpack/loaders/next-style-loader/LICENSE b/packages/next/build/webpack/loaders/next-style-loader/LICENSE new file mode 100644 index 0000000000000..8c11fc7289b75 --- /dev/null +++ b/packages/next/build/webpack/loaders/next-style-loader/LICENSE @@ -0,0 +1,20 @@ +Copyright JS Foundation and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/next/build/webpack/loaders/next-style-loader/index.js b/packages/next/build/webpack/loaders/next-style-loader/index.js new file mode 100644 index 0000000000000..47f56028b9c3f --- /dev/null +++ b/packages/next/build/webpack/loaders/next-style-loader/index.js @@ -0,0 +1,345 @@ +import loaderUtils from 'next/dist/compiled/loader-utils' +import path from 'path' +import { validate } from 'next/dist/compiled/schema-utils3' +import isEqualLocals from './runtime/isEqualLocals' + +const schema = { + type: 'object', + properties: { + injectType: { + description: + 'Allows to setup how styles will be injected into DOM (https://github.com/webpack-contrib/style-loader#injecttype).', + enum: [ + 'styleTag', + 'singletonStyleTag', + 'lazyStyleTag', + 'lazySingletonStyleTag', + 'linkTag', + ], + }, + attributes: { + description: + 'Adds custom attributes to tag (https://github.com/webpack-contrib/style-loader#attributes).', + type: 'object', + }, + insert: { + description: + 'Inserts `