GithubHelp home page GithubHelp logo

webpack-contrib / null-loader Goto Github PK

View Code? Open in Web Editor NEW
145.0 13.0 29.0 1.22 MB

[DEPRECATED] A loader that returns an empty module (can still be used for webpack 4).

License: MIT License

JavaScript 100.00%
webpack-loader

null-loader's Introduction

DEPREACTED

https://webpack.js.org/configuration/resolve/#resolvealias. Setting resolve.alias.package to false will tell webpack@5 to ignore a module.


npm node deps tests chat size

null-loader

A webpack loader that returns an empty module.

One use for this loader is to silence modules imported by a dependency. Say, for example, your project relies on an ES6 library that imports a polyfill you don't need, so removing it will cause no loss in functionality.

Getting Started

To begin, you'll need to install null-loader:

$ npm install null-loader --save-dev

Then add the loader to your webpack config. For example:

// webpack.config.js
const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        // Test for a polyfill (or any file) and it won't be included in your
        // bundle
        test: path.resolve(__dirname, 'node_modules/library/polyfill.js'),
        use: 'null-loader',
      },
    ],
  },
};

And run webpack via your preferred method.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

null-loader's People

Contributors

alexander-akait avatar cap-bernardito avatar evilebottnawi avatar joshwiens avatar shellscape avatar sokra avatar spacek33z avatar xsynaptic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

null-loader's Issues

name

New Feature Use Case

Will be greate possible to change name for output file, for example:

        test: /some-file.*\.less$/,
        loader: NullLoader('[name].css')

License?

Hi can you add a license to this?

Usage

Hi,

can you please add a usage example to the Readme?

Thanks!

Null loader still trying to load sass files

target: 'node',
module: {
        loaders: [
            {
                test: /\.scss$/,
                loader: 'null-loader'
            }
        ]
    }

I try to load a button.js file which refers to a button.scss file. I get the following error:

ERROR in ./app/framework/src/components/button.scss
Module build failed: file to import not found or unreadable: variables
Current dir:  (1:9)
 @ ./app/framework/src/components/button.js 25:0-24
BUILD COMPLETE
[16:49:44] Finished 'test' after 6.38 s
/web/node_modules/babel-core/lib/babel/transformation/file/index.js:614
      throw err;
            ^
SyntaxError: /web/app/framework/src/components/button.scss: Unexpected token (1:0)
> 1 | @import 'variables';
    | ^
  2 | 
  3 | $button-sizes: (
  4 |     'loner-padding'       : 42px,
    at Parser.pp.raise (/web/node_modules/babel-core/lib/acorn/src/location.js:73:13)
    at Parser.pp.unexpected (/web/node_modules/babel-core/lib/acorn/src/parseutil.js:87:8)
    at Parser.pp.parseDecorator (/web/node_modules/babel-core/lib/acorn/src/statement.js:146:10)
    at Parser.pp.parseDecorators (/web/node_modules/babel-core/lib/acorn/src/statement.js:132:31)
    at Parser.pp.parseStatement (/web/node_modules/babel-core/lib/acorn/src/statement.js:46:10)
    at Parser.parseStatement (/web/node_modules/babel-core/lib/acorn/plugins/flow.js:639:22)
    at Parser.pp.parseTopLevel (/web/node_modules/babel-core/lib/acorn/src/statement.js:22:21)
    at Object.parse (/web/node_modules/babel-core/lib/acorn/src/index.js:106:12)
    at exports.default (/web/node_modules/babel-core/lib/babel/helpers/parse.js:66:19)
    at File.parse (/web/node_modules/babel-core/l    at Object.require.extensions..js (/web/test_setup.js:40:11)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/web/app/framework/src/test.entrypoint.js:3:1)
    at Module._compile (module.js:460:26)
    at Object.require.extensions..js (/web/test_setup.js:40:11)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /web/node_modules/mocha/lib/mocha.js:192:27
    at Array.forEach (native)
    at Mocha.loadFiles (/web/node_modules/mocha/lib/mocha.js:189:14)
    at Mocha.run (/web/node_modules/mocha/lib/mocha.js:422:31)
    at Object.<anonymous> (/web/node_modules/mocha/bin/_mocha:398:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Mocha exited with code 1
    at ChildProcess.<anonymous> (/web/node_modules/gulp-spawn-mocha/lib/index.js:58:28)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

If I remove the scss import it works fine, however isn't null loader just supposed to prevent that from loading at all?

Using null-loader to remove/skip fonts specified using url() will corrupt the generated .css file

In my project I'm using Font-Awessome (with scss-loader + file-loader) .... and everything goes fine, and the fonts are put into the proper directory. But I'm looking to "remove some fat" and keep just the .*woff2 files from all of font formats.

I've tried to use "null-loader" to "skip" all other fonts {test: /.(woff|eot|ttf|otf|svg)$/, use: "null-loader"} ... but while the font files are removed, this will corrupt the url() declaration into the generated css file resulting in url([object Object ]) kind of source ...

  • Operating System: Windows
  • Node Version: 9.11.1
  • NPM Version: 5.8.0
  • webpack Version: 4.6.0
  • null-loader Version: 0.1.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

webpack.config.js
  // try to keep just woff2 font and remove all the others
  {  test: /\.woff2$/,  use: "file-loader?name=fonts/[name].[ext]" },
  {  test: /\.(woff|eot|ttf|otf|svg)$/,  use: "null-loader" }

Expected Behavior

  1. The fonts folder should include just fontawesome-webfont.woff2
  2. The generated .css should include just the src: url(fonts/fontawesome-webfont.woff2) format("woff2") declaration:
@font-face {
  font-family: 'FontAwesome';
  src: url(fonts/fontawesome-webfont.woff2) format("woff2")
  font-weight: normal;
  font-style: normal;
}

Actual Behavior

  1. This is ๐Ÿ†— , so just the woff2 font file will be copied
  2. The generated .css will include for ALL non skipped formats an odd url name ( url([object Object]) ) instead of removing the declaration
@font-face {
  font-family: 'FontAwesome';
  src: url([object Object]);
  src: url([object Object]) format("embedded-opentype"), url(fonts/fontawesome-webfont.woff2) format("woff2"), url([object Object]) format("woff"), url([object Object]) format("truetype"), url([object Object]) format("svg");
  font-weight: normal;
  font-style: normal;
}

How Do We Reproduce?

The project reproducing this issue is located here: http://www.github.com/cyparu/null_loader_css_url_bug

Steps to execute:

yarn
yarn build

check build/index.css for wrongly generated CSS content

webpack-defaults upgrade

Addition of webpack-defaults & associated refactoring as a part of the next Major release

Issue exists for status tracking across the organization.

Please do not close

Null-loader takes too much of the build time (possibly not a bug though)

I've been very surprised to see this build time:

Config:

{
  test: /\.(sa|sc|c)ss$/,
  use: 'null-loader',
}

null-loader took 17 seconds for 1000 modules. Considering this loader is supposed to do nothing, this is pretty weird. ignore-loader took ~15-16 seconds which is pretty high as well, that's why I'm thinking this might be a webpack issue, not null-loader issue.

However, babel-loader with thread-loader took way less time, 25 seconds for 5400 modules. I was thinking null-loader is supposed to be faster than that, so faster than 4 seconds per 1000 modules.

Is it possible to speed up null-loader somehow?

  • Operating System: W10
  • Node Version: 10.16.3
  • NPM Version: 6.9.0
  • webpack Version: 4.32.2
  • null-loader Version: 4.0.1, latest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.