File tree Expand file tree Collapse file tree
test/configCases/dll-plugin/3-use-dll-with-hashid Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44*/
55"use strict" ;
66
7+ const path = require ( "path" ) ;
78const Module = require ( "./Module" ) ;
89const OriginalSource = require ( "webpack-sources" ) . OriginalSource ;
910const RawSource = require ( "webpack-sources" ) . RawSource ;
@@ -23,6 +24,20 @@ class DelegatedModule extends Module {
2324 this . delegateData = data ;
2425 }
2526
27+ contextify ( context , request ) {
28+ return request . split ( "!" ) . map ( function ( r ) {
29+ let rp = path . relative ( context , r ) ;
30+ if ( path . sep === "\\" )
31+ rp = rp . replace ( / \\ / g, "/" ) ;
32+ if ( rp . indexOf ( "../" ) !== 0 )
33+ rp = "./" + rp ;
34+ return rp ;
35+ } ) . join ( "!" ) ;
36+ }
37+
38+ libIdent ( options ) {
39+ return this . contextify ( options . context , this . userRequest ) ;
40+ }
2641 identifier ( ) {
2742 return `delegated ${ JSON . stringify ( this . request ) } from ${ this . sourceRequest } ` ;
2843 }
@@ -57,11 +72,7 @@ class DelegatedModule extends Module {
5772 if ( ! sourceModule ) {
5873 str = WebpackMissingModule . moduleCode ( this . sourceRequest ) ;
5974 } else {
60- if ( typeof sourceModule . id === "string" ) {
61- str = `module.exports = (__webpack_require__("${ sourceModule . id } "))` ;
62- } else {
63- str = `module.exports = (__webpack_require__(${ sourceModule . id } ))` ;
64- }
75+ str = `module.exports = (__webpack_require__(${ JSON . stringify ( sourceModule . id ) } ))` ;
6576
6677 switch ( this . type ) {
6778 case "require" :
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ class ExternalModule extends Module {
1818 this . external = true ;
1919 }
2020
21+ libIdent ( ) {
22+ return this . request ;
23+ }
24+
2125 chunkCondition ( chunk ) {
2226 return chunk . hasEntryModule ( ) ;
2327 }
Original file line number Diff line number Diff line change @@ -20,16 +20,10 @@ class HashedModuleIdsPlugin {
2020 const usedIds = new Set ( ) ;
2121 compilation . plugin ( "before-module-ids" , ( modules ) => {
2222 modules . forEach ( ( module ) => {
23- if ( module . id === null ) {
24- let id = "" ;
25- if ( module . libIdent ) {
26- id = module . libIdent ( {
27- context : this . options . context || compiler . options . context
28- } ) ;
29- } else {
30- id = module . identifier ( ) ;
31- }
32-
23+ if ( module . id === null && module . libIdent ) {
24+ const id = module . libIdent ( {
25+ context : this . options . context || compiler . options . context
26+ } ) ;
3327 const hash = createHash ( options . hashFunction ) ;
3428 hash . update ( id ) ;
3529 const hashId = hash . digest ( options . hashDigest ) ;
Original file line number Diff line number Diff line change 1+ export * from "../0-create-dll/e1" ;
2+ export * from "../0-create-dll/e2" ;
Original file line number Diff line number Diff line change 1+ export * from "dll/e1" ;
2+ export * from "dll/e2" ;
Original file line number Diff line number Diff line change 1+ var should = require ( "should" ) ;
2+ import d from "../0-create-dll/d" ;
3+ import { x1 , y2 } from "./e" ;
4+ import { x2 , y1 } from "../0-create-dll/e" ;
5+
6+ it ( "should load a module from dll" , function ( ) {
7+ require ( "../0-create-dll/a" ) . should . be . eql ( "a" ) ;
8+ } ) ;
9+
10+ it ( "should load an async module from dll" , function ( done ) {
11+ require ( "../0-create-dll/b" ) ( ) . then ( function ( c ) {
12+ c . should . be . eql ( { default : "c" } ) ;
13+ done ( ) ;
14+ } ) . catch ( done ) ;
15+ } ) ;
16+
17+ it ( "should load an harmony module from dll (default export)" , function ( ) {
18+ d . should . be . eql ( "d" ) ;
19+ } ) ;
20+
21+ it ( "should load an harmony module from dll (star export)" , function ( ) {
22+ x1 . should . be . eql ( 123 ) ;
23+ x2 . should . be . eql ( 123 ) ;
24+ y1 . should . be . eql ( 456 ) ;
25+ y2 . should . be . eql ( 456 ) ;
26+ } ) ;
27+
28+ it ( "should load a module with loader applied" , function ( ) {
29+ require ( "../0-create-dll/g.abc.js" ) . should . be . eql ( "number" ) ;
30+ } ) ;
31+
32+
Original file line number Diff line number Diff line change 1+ var path = require ( "path" ) ;
2+ var webpack = require ( "../../../../" ) ;
3+
4+ module . exports = {
5+ module : {
6+ rules : [
7+ { oneOf : [
8+ {
9+ test : / \. a b c \. j s $ / ,
10+ loader : "../0-create-dll/g-loader.js" ,
11+ options : {
12+ test : 1
13+ }
14+ }
15+ ] }
16+ ]
17+ } ,
18+ plugins : [
19+ new webpack . DllReferencePlugin ( {
20+ manifest : require ( "../../../js/config/dll-plugin/manifest0.json" ) , // eslint-disable-line node/no-missing-require
21+ name : "../0-create-dll/dll.js" ,
22+ context : path . resolve ( __dirname , "../0-create-dll" ) ,
23+ sourceType : "commonjs2"
24+ } ) ,
25+ new webpack . HashedModuleIdsPlugin ( ) ,
26+ ]
27+ } ;
You can’t perform that action at this time.
0 commit comments