-
-
Save nnennajohn/d1cd32d27adcdc1d6b662d2cf4a24116 to your computer and use it in GitHub Desktop.
Revisions
-
iamakulov revised this gist
May 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Webpack’s ContextReplacementPlugin examples _This is an example to my article [“How webpack’s ContextReplacementPlugin works”](https://iamakulov.com/notes/all/webpack-contextreplacementplugin)_ You have the _moment.js_ library, and you have a dynamic import: -
iamakulov revised this gist
Apr 25, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -59,4 +59,6 @@ new ContextReplacementPlugin( This plugin instance will match all dynamic imports that reference the `/moment[\/\\]locale/` directory. It will change the directory in which webpack should look for the files to `./src/locales` – instead of something like `./node_modules/moment/locales`. Also, it will make webpack match the files against the `/(en-gb|ru)\.js/` regular expression – instead of `/^.*\.js/`. Webpack will still look into subdirectories. _Follow me on Twitter: [@iamakulov](https://twitter.com/iamakulov)_ -
iamakulov revised this gist
Apr 25, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Webpack’s ContextReplacementPlugin examples _[The plugin docs](https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin)_ You have the _moment.js_ library, and you have a dynamic import: -
iamakulov revised this gist
Apr 25, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ # Webpack’s ContextReplacementPlugin examples _[The plugin docs](https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin))_ You have the _moment.js_ library, and you have a dynamic import: -
iamakulov created this gist
Apr 25, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ # ContextReplacementPlugin examples You have the _moment.js_ library, and you have a dynamic import: ```js require('./locale/' + name + '.js') ``` ## Single parameter: directory ```js new ContextReplacementPlugin( /moment[\/\\]locale/, path.resolve(__dirname, './src/locales'), ) ``` This plugin instance will match all dynamic imports that reference the `/moment[\/\\]locale/` directory. It will change the directory in which webpack should look for the files to `./src/locales` – instead of something like `./node_modules/moment/locales`. Webpack will still look into subdirectories and still match the files against `/^.*\.js/` regular expression. ## Single parameter: recursive flag ```js new ContextReplacementPlugin( /moment[\/\\]locale/, false, ) ``` This plugin instance will match all dynamic imports that reference the `/moment[\/\\]locale/` directory. It will make webpack not look in the subdirectories of the root directory. Webpack will still look into the root `./locales` directory and still match the files against `/^.*\.js/` regular expression. ## Single parameter: files regular expression ```js new ContextReplacementPlugin( /moment[\/\\]locale/, /(en-gb|ru)\.js/, ) ``` This plugin instance will match all dynamic imports that reference the `/moment[\/\\]locale/` directory. It will make webpack match the files against the `/(en-gb|ru)\.js/` regular expression – instead of `/^.*\.js/`. Webpack will still look into the root `./locales` directory and still recursively traverse its subdirectories. ## Multiple parameters ```js new ContextReplacementPlugin( /moment[\/\\]locale/, path.resolve(__dirname, './src/locales'), /(en-gb|ru)\.js/, ) ``` This plugin instance will match all dynamic imports that reference the `/moment[\/\\]locale/` directory. It will change the directory in which webpack should look for the files to `./src/locales` – instead of something like `./node_modules/moment/locales`. Also, it will make webpack match the files against the `/(en-gb|ru)\.js/` regular expression – instead of `/^.*\.js/`. Webpack will still look into subdirectories.