• Stars
    star
    260
  • Rank 157,189 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source code handling classes for webpack

webpack-sources

Contains multiple classes which represent a Source. A Source can be asked for source code, size, source map and hash.

Source

Base class for all sources.

Public methods

All methods should be considered as expensive as they may need to do computations.

source

Source.prototype.source() -> String | Buffer

Returns the represented source code as string or Buffer (for binary Sources).

buffer

Source.prototype.buffer() -> Buffer

Returns the represented source code as Buffer. Strings are converted to utf-8.

size

Source.prototype.size() -> Number

Returns the size in bytes of the represented source code.

map

Source.prototype.map(options?: Object) -> Object | null

Returns the SourceMap of the represented source code as JSON. May return null if no SourceMap is available.

The options object can contain the following keys:

  • columns: Boolean (default true): If set to false the implementation may omit mappings for columns.

sourceAndMap

Source.prototype.sourceAndMap(options?: Object) -> {
	source: String | Buffer,
	map: Object | null
}

Returns both, source code (like Source.prototype.source() and SourceMap (like Source.prototype.map()). This method could have better performance than calling source() and map() separately.

See map() for options.

updateHash

Source.prototype.updateHash(hash: Hash) -> void

Updates the provided Hash object with the content of the represented source code. (Hash is an object with an update method, which is called with string values)

RawSource

Represents source code without SourceMap.

new RawSource(sourceCode: String | Buffer)

OriginalSource

Represents source code, which is a copy of the original file.

new OriginalSource(
	sourceCode: String | Buffer,
	name: String
)
  • sourceCode: The source code.
  • name: The filename of the original source code.

OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (;, {, }).

SourceMapSource

Represents source code with SourceMap, optionally having an additional SourceMap for the original source.

new SourceMapSource(
	sourceCode: String | Buffer,
	name: String,
	sourceMap: Object | String | Buffer,
	originalSource?: String | Buffer,
	innerSourceMap?: Object | String | Buffer,
	removeOriginalSource?: boolean
)
  • sourceCode: The source code.
  • name: The filename of the original source code.
  • sourceMap: The SourceMap for the source code.
  • originalSource: The source code of the original file. Can be omitted if the sourceMap already contains the original source code.
  • innerSourceMap: The SourceMap for the originalSource/name.
  • removeOriginalSource: Removes the source code for name from the final map, keeping only the deeper mappings for that file.

The SourceMapSource supports "identity" mappings for the innerSourceMap. When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings from sourceMap.

CachedSource

Decorates a Source and caches returned results of map, source, buffer, size and sourceAndMap in memory. updateHash is not cached. It tries to reused cached results from other methods to avoid calculations, i. e. when source is already cached, calling size will get the size from the cached source, calling sourceAndMap will only call map on the wrapped Source.

new CachedSource(source: Source)
new CachedSource(source: Source | () => Source, cachedData?: CachedData)

Instead of passing a Source object directly one can pass an function that returns a Source object. The function is only called when needed and once.

Public methods

getCachedData()

Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.

original()

Returns the original Source object.

originalLazy()

Returns the original Source object or a function returning these.

PrefixSource

Prefix every line of the decorated Source with a provided string.

new PrefixSource(
	prefix: String,
	source: Source | String | Buffer
)

ConcatSource

Concatenate multiple Sources or strings to a single source.

new ConcatSource(
	...items?: Source | String
)

Public methods

add

ConcatSource.prototype.add(item: Source | String)

Adds an item to the source.

ReplaceSource

Decorates a Source with replacements and insertions of source code.

The ReplaceSource supports "identity" mappings for child source. When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.

Public methods

replace

ReplaceSource.prototype.replace(
	start: Number,
	end: Number,
	replacement: String
)

Replaces chars from start (0-indexed, inclusive) to end (0-indexed, inclusive) with replacement.

Locations represents locations in the original source and are not influenced by other replacements or insertions.

insert

ReplaceSource.prototype.insert(
	pos: Number,
	insertion: String
)

Inserts the insertion before char pos (0-indexed).

Location represents location in the original source and is not influenced by other replacements or insertions.

original

Get decorated Source.

CompatSource

Converts a Source-like object into a real Source object.

Public methods

static from

CompatSource.from(sourceLike: any | Source)

If sourceLike is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.

More Repositories

1

webpack

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
JavaScript
64,550
star
2

webpack-dev-server

Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
JavaScript
7,796
star
3

tapable

Just a little module for plugins.
JavaScript
3,724
star
4

webpack-cli

Webpack's Command Line Interface
JavaScript
2,552
star
5

webpack-dev-middleware

A development middleware for webpack
JavaScript
2,489
star
6

webpack.js.org

Repository for webpack documentation and more!
MDX
2,213
star
7

react-starter

[OUTDATED] Starter template for React with webpack. Doesn't focus on simplicity! NOT FOR BEGINNERS!
JavaScript
2,208
star
8

docs

[OLD] documentation for webpack
JavaScript
1,456
star
9

enhanced-resolve

Offers an async require.resolve function. It's highly configurable.
JavaScript
920
star
10

memory-fs

[DEPRECATED use memfs instead] A simple in-memory filesystem. Holds data in a javascript object.
JavaScript
882
star
11

analyse

analyse web app for webpack stats
JavaScript
879
star
12

webpack-pwa

Example for a super simple PWA with webpack.
JavaScript
809
star
13

loader-utils

utils for webpack loaders
JavaScript
765
star
14

react-webpack-server-side-example

Example of an react application with webpack including server-side rendering.
JavaScript
460
star
15

node-libs-browser

[DEPRECATED] The node core libs for in browser usage.
JavaScript
449
star
16

watchpack

Wrapper library for directory and file watching.
JavaScript
375
star
17

webpack-with-common-libs

webpack with some common libraries
JavaScript
340
star
18

loader-runner

Runs (webpack) loaders
JavaScript
299
star
19

changelog-v5

Temporary repo for the changelog for webpack 5
253
star
20

schema-utils

Options Validation
JavaScript
241
star
21

meeting-notes

Webpack core team meeting notes.
188
star
22

concord

[WIP] concord modules specification
156
star
23

example-app

[OUTDATED] example web app for webpack
JavaScript
138
star
24

fastparse

A very simple and stupid parser, based on a statemachine and regular expressions.
JavaScript
65
star
25

enhanced-require

[CURRENTLY UNMAINTAINED] Enhance the require function in node.js with support for loaders which preprocess files. This is a standalone polyfill for features of webpack.
JavaScript
64
star
26

playground

In-browser playground for webpack
JavaScript
59
star
27

analyse-tool

A tool to analyse your webpack build result. It allows to browse the compilation and points out options to optimize the build.
JavaScript
55
star
28

hot-node-example

Example for HMR in a node.js process
JavaScript
54
star
29

source-list-map

Fast line to line SourceMap generator.
JavaScript
39
star
30

benchmark

Run benchmarks for webpack.
JavaScript
38
star
31

core

[OBSOLETE in webpack 2] The core of webpack and enhanced-require...
JavaScript
26
star
32

media

25
star
33

voting-app

An application for casting votes on new webpack features and fixes.
JavaScript
22
star
34

tooling

A collection of reusable tooling for webpack repos.
JavaScript
20
star
35

graph

[DEPRECATED] Converts JSON stats from webpack to a nice SVG-Image.
JavaScript
13
star
36

template

[DEPRECATED] Create a new web app from a template.
JavaScript
10
star
37

webpack.github.com

webpack.github.com
JavaScript
10
star
38

management

Mission, Goals, projects and budget for webpack
6
star
39

github-org-overview

Scans all repos of a github organization and check if published
JavaScript
5
star
40

the-big-test

[OUTDATED] the big webpack/enhanced-require test
JavaScript
5
star
41

meetup-2018-05-08

QA for the webpack meetup in Munich
4
star
42

v4.webpack.js.org

Hosting for old version of webpack documentation
3
star
43

jquery-wpt-module

[DEPRECATED] webpack-template-module for jquery
JavaScript
2
star
44

bootstrap-wpt-module

[DEPRECATED] webpack-template-module for twitter's bootstrap
JavaScript
2
star
45

github-wiki

The server-side code (heruko) for serving the wiki as gh-pages.
JavaScript
2
star
46

enhanced-resolve-completion-demo

[OUTDATED] demo for the request completion of enhanced-resolve
JavaScript
2
star
47

webpack-tests-example

DEPRECATED (use mocha-loader now): A simple example for doing tests with webpack and mocha.
JavaScript
2
star