storybook/addons/docs/scripts/webpackDllsConfig.js
2020-05-26 15:31:34 +02:00

90 lines
2.5 KiB
JavaScript

import path from 'path';
import { ProgressPlugin, DllPlugin } from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
// eslint-disable-next-line import/no-extraneous-dependencies
import uiPaths from '@storybook/ui/paths';
import themingPaths from '@storybook/theming/paths';
const resolveLocal = (dir) => path.join(__dirname, dir);
const r = resolveLocal('../../../node_modules');
const out = resolveLocal('../../../lib/core/dll');
export default ({ entry, provided = [] }) => ({
name: 'storybook-docs',
mode: 'development',
entry,
output: {
path: out,
filename: 'storybook_docs_dll.js',
library: 'storybook_docs_dll',
},
externals: provided,
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
sourceType: 'unambiguous',
plugins: [
require.resolve('@babel/plugin-transform-shorthand-properties'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
require.resolve('@babel/plugin-transform-template-literals'),
require.resolve('@babel/plugin-transform-block-scoping'),
require.resolve('@babel/plugin-transform-classes'),
require.resolve('@babel/plugin-transform-arrow-functions'),
require.resolve('@babel/plugin-transform-parameters'),
require.resolve('@babel/plugin-transform-destructuring'),
require.resolve('@babel/plugin-transform-spread'),
require.resolve('@babel/plugin-transform-for-of'),
],
},
},
],
},
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.json'],
modules: [path.join(__dirname, '../../../node_modules')],
alias: {
...themingPaths,
...uiPaths,
semver: require.resolve('@storybook/semver'),
},
},
plugins: [
new ProgressPlugin(),
new DllPlugin({
context: r,
path: `${out}/storybook_docs-manifest.json`,
name: 'storybook_docs_dll',
}),
],
optimization: {
concatenateModules: true,
portableRecords: true,
moduleIds: 'hashed',
minimizer: [
new TerserPlugin({
extractComments: {
condition: /^\**!|@preserve|@license|@cc_on/i,
filename: (file) => file.replace('.js', '.LICENCE'),
banner: (licenseFile) => `License information can be found in ${licenseFile}`,
},
}),
],
},
performance: {
hints: false,
},
});