Skip to content

Commit

Permalink
feat: Webpack loader inlining (#21127)
Browse files Browse the repository at this point in the history
This picks up on the inlining work in #20598 to also include webpack loader inlining optimizations.

This includes:
* The dependencies of sass-loader
* resolve-url-loader

And for added benefit:
* babel-plugin-transform-define
* babel-plugin-transform-react-remove-prop-types

style-loader and css-loader didn't inline easily. Perhaps we can come back to these ones.
  • Loading branch information
guybedford committed Jan 15, 2021
1 parent dc87a84 commit 005a8ab
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/babel/preset.ts
Expand Up @@ -198,7 +198,7 @@ module.exports = (
],
require('./plugins/amp-attributes'),
isProduction && [
require('babel-plugin-transform-react-remove-prop-types'),
require('next/dist/compiled/babel/plugin-transform-react-remove-prop-types'),
{
removeImport: true,
},
Expand Down
@@ -1,4 +1,4 @@
import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'
import path from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack'

Expand Down
@@ -1,5 +1,5 @@
// import babel from 'next/dist/compiled/babel/core'
import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'
import { tracer, traceAsyncFn, traceFn } from '../../../../tracer'
import cache from './cache'
import transform from './transform'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/emit-file-loader.js
@@ -1,4 +1,4 @@
import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'

module.exports = function (content, sourceMap) {
this.cacheable()
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/error-loader.ts
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'
import path from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack'

Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-babel-loader.js
Expand Up @@ -155,7 +155,7 @@ const customBabelLoader = babelLoader((babel) => {
}

options.plugins.push([
require.resolve('babel-plugin-transform-define'),
require.resolve('next/dist/compiled/babel/plugin-transform-define'),
{
'process.env.NODE_ENV': development ? 'development' : 'production',
'typeof window': isServer ? 'undefined' : 'object',
Expand Down
@@ -1,4 +1,4 @@
import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'
import { tracer, traceFn } from '../../tracer'

export type ClientPagesLoaderOptions = {
Expand Down
@@ -1,6 +1,6 @@
import NativeModule from 'module'

import loaderUtils from 'loader-utils'
import loaderUtils from 'next/dist/compiled/loader-utils'
import {
webpack,
isWebpack5,
Expand Down
10 changes: 10 additions & 0 deletions packages/next/bundles/babel/bundle.js
Expand Up @@ -36,10 +36,18 @@ function pluginSyntaxJsx() {
return require('@babel/plugin-syntax-jsx')
}

function pluginTransformDefine() {
return require('babel-plugin-transform-define')
}

function pluginTransformModulesCommonjs() {
return require('@babel/plugin-transform-modules-commonjs')
}

function pluginTransformReactRemovePropTypes() {
return require('babel-plugin-transform-react-remove-prop-types')
}

function pluginTransformRuntime() {
return require('@babel/plugin-transform-runtime')
}
Expand All @@ -66,7 +74,9 @@ module.exports = {
pluginSyntaxBigint,
pluginSyntaxDynamicImport,
pluginSyntaxJsx,
pluginTransformDefine,
pluginTransformModulesCommonjs,
pluginTransformReactRemovePropTypes,
pluginTransformRuntime,
presetEnv,
presetReact,
Expand Down
@@ -0,0 +1 @@
module.exports = require('./bundle').pluginTransformDefine()
@@ -0,0 +1 @@
module.exports = require('./bundle').pluginTransformReactRemovePropTypes()
8 changes: 4 additions & 4 deletions packages/next/compiled/babel/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/next/compiled/babel/plugin-transform-define.js
@@ -0,0 +1 @@
module.exports = require('./bundle').pluginTransformDefine()
@@ -0,0 +1 @@
module.exports = require('./bundle').pluginTransformReactRemovePropTypes()
2 changes: 1 addition & 1 deletion packages/next/compiled/cache-loader/cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/compiled/file-loader/cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/next/compiled/loader-utils/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.
1 change: 1 addition & 0 deletions packages/next/compiled/loader-utils/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/next/compiled/loader-utils/package.json
@@ -0,0 +1 @@
{"name":"loader-utils","main":"index.js","author":"Tobias Koppers @sokra","license":"MIT"}
2 changes: 1 addition & 1 deletion packages/next/compiled/postcss-loader/cjs.js

Large diffs are not rendered by default.

0 comments on commit 005a8ab

Please sign in to comment.