@grafana/toolkit: webpack extend TS→JS (#21176)

This commit is contained in:
Steven Vachon 2019-12-18 13:47:03 -05:00 committed by Ryan McKinley
parent 06347e3f86
commit 7aeba652c9
7 changed files with 24 additions and 29 deletions

View File

@ -129,23 +129,20 @@ Currently we support following Jest configuration properties:
### How can I customize Webpack rules or plugins?
You can provide your own webpack configuration.
Provide a function implementing `CustomWebpackConfigurationGetter` in a file named `webpack.config.ts`.
Provide a function implementing `CustomWebpackConfigurationGetter` in a file named `webpack.config.js`.
You can import the correct interface and Options from `@grafana/toolkit/src/config`.
Example
``` ts
import { CustomWebpackConfigurationGetter } from '@grafana/toolkit/src/config'
```js
import CustomPlugin from 'custom-plugin';
const getWebpackConfig: CustomWebpackConfigurationGetter = (defaultConfig, options) => {
export const getWebpackConfig = (defaultConfig, options) => {
console.log('Custom config');
defaultConfig.plugins.push(new CustomPlugin())
return defaultConfig;
}
export = getWebpackConfig;
};
```
### How can I style my plugin?

View File

@ -0,0 +1,10 @@
'use strict';
const {cloneDeep} = require('lodash');
const overrideWebpackConfig = (originalConfig, options) => {
const config = cloneDeep(originalConfig);
config.name = 'customConfig';
return config;
};
module.exports = overrideWebpackConfig;

View File

@ -1,10 +0,0 @@
import { CustomWebpackConfigurationGetter } from '../../../webpack.plugin.config';
import _ from 'lodash';
const overrideWebpackConfig: CustomWebpackConfigurationGetter = (originalConfig, options) => {
const config = _.cloneDeep(originalConfig);
config.name = 'customConfig';
return config;
};
export = overrideWebpackConfig;

View File

@ -0,0 +1,8 @@
'use strict';
const {cloneDeep} = require('lodash');
module.exports.getWebpackConfig = (originalConfig, options) => {
const config = cloneDeep(originalConfig);
config.name = 'customConfig';
return config;
};

View File

@ -1,8 +0,0 @@
import { CustomWebpackConfigurationGetter } from '../../../webpack.plugin.config';
import _ from 'lodash';
export const getWebpackConfig: CustomWebpackConfigurationGetter = (originalConfig, options) => {
const config = _.cloneDeep(originalConfig);
config.name = 'customConfig';
return config;
};

View File

@ -1,7 +1,5 @@
/* WRONG CONFIG ON PURPOSE - DO NOT COPY THIS */
const config = {
module.exports.config = {
name: 'test',
};
export = config;

View File

@ -235,7 +235,7 @@ const getBaseWebpackConfig: WebpackConfigurationGetter = async options => {
export const loadWebpackConfig: WebpackConfigurationGetter = async options => {
const baseConfig = await getBaseWebpackConfig(options);
const customWebpackPath = path.resolve(process.cwd(), 'webpack.config.ts');
const customWebpackPath = path.resolve(process.cwd(), 'webpack.config.js');
try {
await accessPromise(customWebpackPath);