Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
265fc59
commit 84933cc
Showing
10 changed files
with
165 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default class CssDependencyTemplate { | ||
// eslint-disable-next-line class-methods-use-this | ||
apply() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import webpack from 'webpack'; | ||
|
||
import { MODULE_TYPE } from './utils'; | ||
|
||
export default class CssModule extends webpack.Module { | ||
constructor(dependency) { | ||
super(MODULE_TYPE, dependency.context); | ||
|
||
this.id = ''; | ||
this._identifier = dependency.identifier; | ||
this._identifierIndex = dependency.identifierIndex; | ||
this.content = dependency.content; | ||
this.media = dependency.media; | ||
this.sourceMap = dependency.sourceMap; | ||
} | ||
|
||
// no source() so webpack doesn't do add stuff to the bundle | ||
|
||
size() { | ||
return this.content.length; | ||
} | ||
|
||
identifier() { | ||
return `css ${this._identifier} ${this._identifierIndex}`; | ||
} | ||
|
||
readableIdentifier(requestShortener) { | ||
return `css ${requestShortener.shorten(this._identifier)}${ | ||
this._identifierIndex ? ` (${this._identifierIndex})` : '' | ||
}`; | ||
} | ||
|
||
nameForCondition() { | ||
const resource = this._identifier.split('!').pop(); | ||
const idx = resource.indexOf('?'); | ||
|
||
if (idx >= 0) { | ||
return resource.substring(0, idx); | ||
} | ||
|
||
return resource; | ||
} | ||
|
||
updateCacheModule(module) { | ||
this.content = module.content; | ||
this.media = module.media; | ||
this.sourceMap = module.sourceMap; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
needRebuild() { | ||
return true; | ||
} | ||
|
||
build(options, compilation, resolver, fileSystem, callback) { | ||
this.buildInfo = {}; | ||
this.buildMeta = {}; | ||
callback(); | ||
} | ||
|
||
updateHash(hash, context) { | ||
super.updateHash(hash, context); | ||
|
||
hash.update(this.content); | ||
hash.update(this.media || ''); | ||
hash.update(this.sourceMap ? JSON.stringify(this.sourceMap) : ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import CssModule from './CssModule'; | ||
|
||
export default class CssModuleFactory { | ||
// eslint-disable-next-line class-methods-use-this | ||
create({ dependencies: [dependency] }, callback) { | ||
callback(null, new CssModule(dependency)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import NativeModule from 'module'; | ||
|
||
const MODULE_TYPE = 'css/mini-extract'; | ||
|
||
function findModuleById(compilation, id) { | ||
const { modules, chunkGraph } = compilation; | ||
|
||
for (const module of modules) { | ||
const moduleId = | ||
typeof chunkGraph !== 'undefined' | ||
? chunkGraph.getModuleId(module) | ||
: module.id; | ||
|
||
if (moduleId === id) { | ||
return module; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function evalModuleCode(loaderContext, code, filename) { | ||
const module = new NativeModule(filename, loaderContext); | ||
|
||
module.paths = NativeModule._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle | ||
module.filename = filename; | ||
module._compile(code, filename); // eslint-disable-line no-underscore-dangle | ||
|
||
return module.exports; | ||
} | ||
|
||
function compareIds(a, b) { | ||
if (typeof a !== typeof b) { | ||
return typeof a < typeof b ? -1 : 1; | ||
} | ||
|
||
if (a < b) { | ||
return -1; | ||
} | ||
|
||
if (a > b) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function compareModulesByIdentifier(a, b) { | ||
return compareIds(a.identifier(), b.identifier()); | ||
} | ||
|
||
export { | ||
MODULE_TYPE, | ||
findModuleById, | ||
evalModuleCode, | ||
compareModulesByIdentifier, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.