diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 40b77e9..16c3b8a 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,5 +1,6 @@ import type webpack from 'webpack'; import type { WebpackOptions } from 'types'; +import getProvidePlugin from './provide-plugin'; import getBundleAnalyzerPlugin from './bundle-analyzer-plugin'; import getCopyPlugin from './copy-plugin'; import getDefinePlugin from './define-plugin'; @@ -20,6 +21,7 @@ const createPlugins = (options: WebpackOptions): webpack.Configuration['plugins' const developmentPlugins = [ getHtmlPlugin(options), getProgressPlugin(options), + getProvidePlugin(options), getDefinePlugin(options), getForkTsCheckerPlugin(options), getEslintPlugin(options), @@ -29,6 +31,7 @@ const createPlugins = (options: WebpackOptions): webpack.Configuration['plugins' const productionPlugins = [ getHtmlPlugin(options), + getProvidePlugin(options), getDefinePlugin(options), getMiniCssPlugin(options), getForkTsCheckerPlugin(options), diff --git a/src/plugins/provide-plugin/index.ts b/src/plugins/provide-plugin/index.ts new file mode 100644 index 0000000..f7f97c2 --- /dev/null +++ b/src/plugins/provide-plugin/index.ts @@ -0,0 +1,21 @@ +import type { WebpackOptions } from 'types'; +import { ProvidePlugin } from 'webpack'; + +const getProvidePlugin = (options: WebpackOptions) => { + const { + plugins: { + providePlugin, + } = {}, + } = options; + + if (providePlugin === 'off') { + return null; + } + + return new ProvidePlugin({ + process: 'process/browser', + ...providePlugin, + }); +}; + +export default getProvidePlugin;