Skip to content

Commit 98a9647

Browse files
author
Tobias Sailer
committed
feat(image-config-webpack-plugin, font-config-webpack-plugin): add configuration to enable ESModules
Add a option to make the switch between CommonJS and ES module type imports
1 parent ef105b8 commit 98a9647

File tree

10 files changed

+7512
-9
lines changed

10 files changed

+7512
-9
lines changed

packages/font-config-webpack-plugin/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ module.exports = {
5252
],
5353
};
5454
```
55+
56+
### Enable ES module syntax
57+
58+
By default the `font-config-webpack-plugin` uses the CommonJS modules syntax (`require` statements).
59+
You can enable the ES module syntax (`import` statements) syntax using: `esModule: true` in the options.
60+
61+
For more information see [file-loader documentation](https://v4.webpack.js.org/loaders/file-loader/#esmodule)
62+
63+
```js
64+
const FontConfigWebpackPlugin = require('font-config-webpack-plugin');
65+
module.exports = {
66+
plugins: [
67+
new FontConfigWebpackPlugin({
68+
esModule: true,
69+
}),
70+
],
71+
};
72+
```

packages/font-config-webpack-plugin/config/development.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports = module.exports = (options) => ({
1414
loader: require.resolve('file-loader'),
1515
options: {
1616
name: options.name,
17-
esModule: false,
17+
esModule: options.esModule,
1818
},
1919
},
2020
],

packages/font-config-webpack-plugin/src/FontConfigWebpackPlugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
* Plugin Options
99
* @typedef {{
1010
mode?: 'production' | 'development'
11-
name: string,
11+
esModule?: boolean
12+
name: string
1213
}} FontConfigWebpackPluginOptions */
1314

1415
'use strict';
1516
/**
1617
* @type {FontConfigWebpackPluginOptions}
1718
*/
18-
const defaultOptions = { name: 'static/media/[name].[hash:8].[ext]' };
19+
const defaultOptions = { name: 'static/media/[name].[hash:8].[ext]', esModule: false };
1920

2021
class FontConfigWebpackPlugin {
2122
/**

packages/font-config-webpack-plugin/test/FontConfigWebpackPlugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('FontConfigWebpackPlugin standalone', () => {
2626
});
2727

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

3232
expect(instance.options).toEqual(options);

packages/image-config-webpack-plugin/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ module.exports = {
5252
],
5353
};
5454
```
55+
56+
### Enable ES module syntax
57+
58+
By default the `image-config-webpack-plugin` uses the CommonJS modules syntax (`require` statements).
59+
You can enable the ES module syntax (`import` statements) syntax using: `esModule: true` in the options.
60+
61+
For more information see [file-loader documentation](https://v4.webpack.js.org/loaders/file-loader/#esmodule)
62+
63+
```js
64+
const ImageConfigWebpackPlugin = require('image-config-webpack-plugin');
65+
module.exports = {
66+
plugins: [
67+
new ImageConfigWebpackPlugin({
68+
esModule: true,
69+
}),
70+
],
71+
};
72+
```

packages/image-config-webpack-plugin/config/development.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports = module.exports = (options) => ({
1414
loader: require.resolve('file-loader'),
1515
options: {
1616
name: options.name,
17-
esModule: false,
17+
esModule: options.esModule,
1818
},
1919
},
2020
],

packages/image-config-webpack-plugin/config/production.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports = module.exports = (options) => ({
1515
options: {
1616
name: options.name,
1717
limit: 512,
18-
esModule: false,
18+
esModule: options.esModule,
1919
},
2020
},
2121
],

0 commit comments

Comments
 (0)