Skip to content

Commit

Permalink
feat(image-config-webpack-plugin, font-config-webpack-plugin): add co…
Browse files Browse the repository at this point in the history
…nfiguration to enable ESModules

Add a option to make the switch between CommonJS and ES module type imports
  • Loading branch information
Tobias Sailer committed Aug 13, 2021
1 parent ef105b8 commit 98a9647
Show file tree
Hide file tree
Showing 10 changed files with 7,512 additions and 9 deletions.
18 changes: 18 additions & 0 deletions packages/font-config-webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ module.exports = {
],
};
```

### Enable ES module syntax

By default the `font-config-webpack-plugin` uses the CommonJS modules syntax (`require` statements).
You can enable the ES module syntax (`import` statements) syntax using: `esModule: true` in the options.

For more information see [file-loader documentation](https://v4.webpack.js.org/loaders/file-loader/#esmodule)

```js
const FontConfigWebpackPlugin = require('font-config-webpack-plugin');
module.exports = {
plugins: [
new FontConfigWebpackPlugin({
esModule: true,
}),
],
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports = module.exports = (options) => ({
loader: require.resolve('file-loader'),
options: {
name: options.name,
esModule: false,
esModule: options.esModule,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
* Plugin Options
* @typedef {{
mode?: 'production' | 'development'
name: string,
esModule?: boolean
name: string
}} FontConfigWebpackPluginOptions */

'use strict';
/**
* @type {FontConfigWebpackPluginOptions}
*/
const defaultOptions = { name: 'static/media/[name].[hash:8].[ext]' };
const defaultOptions = { name: 'static/media/[name].[hash:8].[ext]', esModule: false };

class FontConfigWebpackPlugin {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('FontConfigWebpackPlugin standalone', () => {
});

it('should return an instance with the options assigned to it', () => {
const options = { name: '[hash]-[name].[ext]' };
const options = { name: '[hash]-[name].[ext]', esModule: false };
const instance = new FontConfigWebpackPlugin(options);

expect(instance.options).toEqual(options);
Expand Down
18 changes: 18 additions & 0 deletions packages/image-config-webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ module.exports = {
],
};
```

### Enable ES module syntax

By default the `image-config-webpack-plugin` uses the CommonJS modules syntax (`require` statements).
You can enable the ES module syntax (`import` statements) syntax using: `esModule: true` in the options.

For more information see [file-loader documentation](https://v4.webpack.js.org/loaders/file-loader/#esmodule)

```js
const ImageConfigWebpackPlugin = require('image-config-webpack-plugin');
module.exports = {
plugins: [
new ImageConfigWebpackPlugin({
esModule: true,
}),
],
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports = module.exports = (options) => ({
loader: require.resolve('file-loader'),
options: {
name: options.name,
esModule: false,
esModule: options.esModule,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports = module.exports = (options) => ({
options: {
name: options.name,
limit: 512,
esModule: false,
esModule: options.esModule,
},
},
],
Expand Down
Loading

0 comments on commit 98a9647

Please sign in to comment.