@@ -143,8 +143,12 @@ corresponds to the `years` parameter in the target module exported function:
143143``` js
144144module .exports = function yearsInMs ({ years }) {
145145 const value = years * 365 * 24 * 60 * 60 * 1000 ;
146+
146147 // NOTE: this return value will replace the module in the bundle
147- return { code: ' module.exports = ' + value };
148+ return {
149+ cacheable: true ,
150+ code: ' module.exports = ' + value,
151+ };
148152};
149153```
150154
@@ -173,22 +177,81 @@ module.exports = {
173177In the bundle, requiring the module then returns:
174178
175179``` js
176- // ... bundle code ...
180+ import tenYearsMs from ' years-in-ms ' ;
177181
178- const tenYearsMs = require ( ' years-in-ms ' ); // 315360000000
182+ console . log (tenYearsMs ); // 315360000000
179183```
180184
185+ ### Modernizr
186+
187+ Example shows how to build [ ` modernizr ` ] ( https://www.npmjs.com/package/modernizr ) .
188+
189+ ** entry.js**
190+
181191``` js
182- // ... bundle code ...
192+ import modenizr from ' ./modernizr.js' ;
193+ ```
183194
184- require (' val-loader!tenyearsinms' ) == 315360000000 ;
195+ ** modernizr.js**
196+
197+ ``` js
198+ const modernizr = require (' modernizr' );
199+
200+ module .exports = function (options ) {
201+ return new Promise (function (resolve ) {
202+ // It is impossible to throw an error because modernizr causes the process.exit(1)
203+ modernizr .build (options, function (output ) {
204+ resolve ({
205+ cacheable: true ,
206+ code: ` var modernizr; var hadGlobal = 'Modernizr' in window; var oldGlobal = window.Modernizr; ${ output} modernizr = window.Modernizr; if (hadGlobal) { window.Modernizr = oldGlobal; } else { delete window.Modernizr; } export default modernizr;` ,
207+ });
208+ });
209+ });
210+ };
211+ ```
212+
213+ ** webpack.config.js**
214+
215+ ``` js
216+ const path = require (' path' );
217+ module .exports = {
218+ module: {
219+ rules: [
220+ {
221+ test: path .resolve (__dirname , ' src' , ' modernizr.js' ),
222+ use: [
223+ {
224+ loader: ' val-loader' ,
225+ options: {
226+ minify: false ,
227+ options: [' setClasses' ],
228+ ' feature-detects' : [
229+ ' test/css/flexbox' ,
230+ ' test/es6/promises' ,
231+ ' test/serviceworker' ,
232+ ],
233+ },
234+ },
235+ ],
236+ },
237+ ],
238+ },
239+ };
185240```
186241
187242### Figlet
188243
189- Example shows how to build [ ` figlet ` ] ( https://www.npmjs.com/package/figlet )
244+ Example shows how to build [ ` figlet ` ] ( https://www.npmjs.com/package/figlet ) .
245+
246+ ** entry.js**
247+
248+ ``` js
249+ import { default as figlet } from ' ./figlet.js' ;
190250
191- ** src/figlet.js**
251+ console .log (figlet);
252+ ```
253+
254+ ** figlet.js**
192255
193256``` js
194257const figlet = require (' figlet' );
@@ -211,7 +274,7 @@ function wrapOutput(output, config) {
211274 return ` module.exports = decodeURI("${ figletOutput} ");` ;
212275}
213276
214- module .exports = function (options ) {
277+ module .exports = function (options ) {
215278 const defaultConfig = {
216279 fontOptions: {
217280 font: ' ANSI Shadow' ,
@@ -226,13 +289,14 @@ module.exports = function(options) {
226289
227290 const config = Object .assign ({}, defaultConfig, options);
228291
229- return new Promise (function (resolve , reject ) {
292+ return new Promise (function (resolve , reject ) {
230293 figlet .text (config .text , config .fontOptions , (error , output ) => {
231294 if (error) {
232295 return reject (error);
233296 }
234297
235298 resolve ({
299+ cacheable: true ,
236300 code: ' module.exports = ' + wrapOutput (output, config),
237301 });
238302 });
@@ -263,70 +327,6 @@ module.exports = {
263327};
264328```
265329
266- ** src/entry.js**
267-
268- ``` js
269- import { default as figlet } from ' ./figlet.js' ;
270- console .log (figlet);
271- ```
272-
273- ### Modernizr
274-
275- Example shows how to build [ ` modernizr ` ] ( https://www.npmjs.com/package/modernizr )
276-
277- ** src/modernizr.js**
278-
279- ``` js
280- const modernizr = require (' modernizr' );
281-
282- module .exports = function (options ) {
283- return new Promise (function (resolve ) {
284- // It is impossible to throw an error because modernizr causes the process.exit(1)
285- modernizr .build (options, function (output ) {
286- resolve ({
287- cacheable: true ,
288- code: ` var modernizr; var hadGlobal = 'Modernizr' in window; var oldGlobal = window.Modernizr; ${ output} modernizr = window.Modernizr; if (hadGlobal) { window.Modernizr = oldGlobal; } else { delete window.Modernizr; } export default modernizr;` ,
289- });
290- });
291- });
292- };
293- ```
294-
295- ** webpack.config.js**
296-
297- ``` js
298- const path = require (' path' );
299- module .exports = {
300- module: {
301- rules: [
302- {
303- test: path .resolve (__dirname , ' src' , ' modernizr.js' ),
304- use: [
305- {
306- loader: ' val-loader' ,
307- options: {
308- minify: false ,
309- options: [' setClasses' ],
310- ' feature-detects' : [
311- ' test/css/flexbox' ,
312- ' test/es6/promises' ,
313- ' test/serviceworker' ,
314- ],
315- },
316- },
317- ],
318- },
319- ],
320- },
321- };
322- ```
323-
324- ** src/entry.js**
325-
326- ``` js
327- import modenizr from ' ./modernizr.js' ;
328- ```
329-
330330## Contributing
331331
332332Please take a moment to read our contributing guidelines if you haven't yet done so.
@@ -343,8 +343,8 @@ Please take a moment to read our contributing guidelines if you haven't yet done
343343[ node-url ] : https://nodejs.org
344344[ deps ] : https://david-dm.org/webpack-contrib/val-loader.svg
345345[ deps-url ] : https://david-dm.org/webpack-contrib/val-loader
346- [ tests ] : https://dev.azure. com/webpack-contrib/val-loader/_apis/build/status/webpack-contrib. val-loader?branchName=master
347- [ tests-url ] : https://dev.azure. com/webpack-contrib/val-loader/_build/latest?definitionId=2&branchName=master
346+ [ tests ] : https://github. com/webpack-contrib/val-loader/workflows/ val-loader/badge.svg
347+ [ tests-url ] : https://github. com/webpack-contrib/val-loader/actions
348348[ cover ] : https://codecov.io/gh/webpack-contrib/val-loader/branch/master/graph/badge.svg
349349[ cover-url ] : https://codecov.io/gh/webpack-contrib/val-loader
350350[ chat ] : https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
0 commit comments