File tree Expand file tree Collapse file tree 9 files changed +106
-3
lines changed
configCases/loaders/pre-post-loader Expand file tree Collapse file tree 9 files changed +106
-3
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ class NormalModuleFactory extends Tapable {
143143
144144 const noAutoLoaders = / ^ - ? ! / . test ( request ) ;
145145 const noPrePostAutoLoaders = / ^ ! ! / . test ( request ) ;
146- const noPostAutoLoaders = / ^ - ! / . test ( request ) ;
146+ const noPreAutoLoaders = / ^ - ! / . test ( request ) ;
147147 let elements = request . replace ( / ^ - ? ! + / , "" ) . replace ( / ! ! + / g, "!" ) . split ( "!" ) ;
148148 let resource = elements . pop ( ) ;
149149 elements = elements . map ( identToLoaderRequest ) ;
@@ -220,9 +220,9 @@ class NormalModuleFactory extends Tapable {
220220 const useLoadersPre = [ ] ;
221221 result . forEach ( r => {
222222 if ( r . type === "use" ) {
223- if ( r . enforce === "post" && ! noPostAutoLoaders && ! noPrePostAutoLoaders )
223+ if ( r . enforce === "post" && ! noPrePostAutoLoaders )
224224 useLoadersPost . push ( r . value ) ;
225- else if ( r . enforce === "pre" && ! noPrePostAutoLoaders )
225+ else if ( r . enforce === "pre" && ! noPreAutoLoaders && ! noPrePostAutoLoaders )
226226 useLoadersPre . push ( r . value ) ;
227227 else if ( ! r . enforce && ! noAutoLoaders && ! noPrePostAutoLoaders )
228228 useLoaders . push ( r . value ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const sinon = require("sinon");
88const webpack = require ( "../" ) ;
99const WebpackOptionsDefaulter = require ( "../lib/WebpackOptionsDefaulter" ) ;
1010const Compiler = require ( "../lib/Compiler" ) ;
11+ const MemoryFs = require ( "memory-fs" ) ;
1112
1213describe ( "Compiler" , ( ) => {
1314 function compile ( entry , options , callback ) {
@@ -242,6 +243,24 @@ describe("Compiler", () => {
242243 } ) ;
243244 } ) ;
244245 } ) ;
246+ it ( "should not emit on errors" , function ( done ) {
247+ const compiler = webpack ( {
248+ context : __dirname ,
249+ mode : "production" ,
250+ entry : "./missing" ,
251+ output : {
252+ path : "/" ,
253+ filename : "bundle.js"
254+ }
255+ } ) ;
256+ compiler . outputFileSystem = new MemoryFs ( ) ;
257+ compiler . run ( ( err , stats ) => {
258+ if ( err ) return done ( err ) ;
259+ if ( compiler . outputFileSystem . existsSync ( "/bundle.js" ) )
260+ return done ( new Error ( "Bundle should not be created on error" ) ) ;
261+ done ( ) ;
262+ } ) ;
263+ } ) ;
245264 describe ( "Watching" , ( ) => {
246265 let compiler ;
247266 beforeEach ( ( ) => {
Original file line number Diff line number Diff line change 1+ /*globals describe it */
2+ "use strict" ;
3+
4+ require ( "should" ) ;
5+
6+ const webpack = require ( "../lib/webpack" ) ;
7+ const MemoryFs = require ( "memory-fs" ) ;
8+
9+ describe ( "Stats" , ( ) => {
10+ it ( "should print env string in stats" , function ( done ) {
11+ const compiler = webpack ( {
12+ context : __dirname ,
13+ entry : "./fixtures/a"
14+ } ) ;
15+ compiler . outputFileSystem = new MemoryFs ( ) ;
16+ compiler . run ( ( err , stats ) => {
17+ if ( err ) return done ( err ) ;
18+ try {
19+ stats . toString ( {
20+ all : false ,
21+ env : true ,
22+ _env : "production"
23+ } ) . should . be . eql (
24+ "Environment (--env): \"production\""
25+ ) ;
26+ stats . toString ( {
27+ all : false ,
28+ env : true ,
29+ _env : {
30+ prod : [ "foo" , "bar" ] ,
31+ baz : true
32+ }
33+ } ) . should . be . eql (
34+ "Environment (--env): {\n" +
35+ " \"prod\": [\n" +
36+ " \"foo\",\n" +
37+ " \"bar\"\n" +
38+ " ],\n" +
39+ " \"baz\": true\n" +
40+ "}"
41+ ) ;
42+ done ( ) ;
43+ } catch ( e ) {
44+ done ( e ) ;
45+ }
46+ } ) ;
47+ } ) ;
48+ } ) ;
Original file line number Diff line number Diff line change 1+ module . exports = "resource" ;
Original file line number Diff line number Diff line change 1+ it ( "should apply pre and post loaders correctly" , function ( ) {
2+ require ( "./a" ) . should . be . eql ( "resource loader2 loader1 loader3" ) ;
3+ require ( "!./a" ) . should . be . eql ( "resource loader2 loader3" ) ;
4+ require ( "!!./a" ) . should . be . eql ( "resource" ) ;
5+ require ( "-!./a" ) . should . be . eql ( "resource loader3" ) ;
6+ } ) ;
Original file line number Diff line number Diff line change 1+ module . exports = function ( source ) {
2+ return source + "module.exports += \" loader1\";\n" ;
3+ } ;
Original file line number Diff line number Diff line change 1+ module . exports = function ( source ) {
2+ return source + "module.exports += \" loader2\";\n" ;
3+ } ;
Original file line number Diff line number Diff line change 1+ module . exports = function ( source ) {
2+ return source + "module.exports += \" loader3\";\n" ;
3+ } ;
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ module : {
3+ rules : [
4+ {
5+ test : / a \. j s $ / ,
6+ use : "./loader1" ,
7+ } ,
8+ {
9+ test : / a \. j s $ / ,
10+ use : "./loader2" ,
11+ enforce : "pre"
12+ } ,
13+ {
14+ test : / a \. j s $ / ,
15+ use : "./loader3" ,
16+ enforce : "post"
17+ }
18+ ]
19+ }
20+ } ;
You can’t perform that action at this time.
0 commit comments