-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
manager-webpack.config.js
136 lines (130 loc) · 3.94 KB
/
manager-webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import path from 'path';
import webpack, { DefinePlugin, ContextReplacementPlugin } from 'webpack';
import Dotenv from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import CoreJSUpgradeWebpackPlugin from 'corejs-upgrade-webpack-plugin';
import themingPaths from '@storybook/theming/paths';
import uiPaths from '@storybook/ui/paths';
import findCacheDir from 'find-cache-dir';
import { version } from '../../../package.json';
import { getManagerHeadHtml } from '../utils/template';
import { loadEnv } from '../config/utils';
import babelLoader from '../common/babel-loader';
const coreDirName = path.dirname(require.resolve('@storybook/core/package.json'));
const context = path.join(coreDirName, '../../node_modules');
const cacheDir = findCacheDir({ name: 'storybook' });
export default ({
configDir,
configType,
docsMode,
entries,
dll,
outputDir,
cache,
babelOptions,
previewUrl,
}) => {
const { raw, stringified } = loadEnv();
const isProd = configType === 'PRODUCTION';
return {
name: 'manager',
mode: isProd ? 'production' : 'development',
bail: isProd,
devtool: 'none',
entry: entries,
output: {
path: outputDir,
filename: '[name].[chunkhash].bundle.js',
publicPath: '',
},
cache,
plugins: [
dll
? new webpack.DllReferencePlugin({
context,
manifest: path.join(__dirname, '../../../dll/storybook_ui-manifest.json'),
})
: null,
new HtmlWebpackPlugin({
filename: `index.html`,
chunksSortMode: 'none',
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, options) => ({
compilation,
files,
options,
version,
dlls: dll ? ['./sb_dll/storybook_ui_dll.js'] : [],
globals: {
DOCS_MODE: docsMode, // global docs mode
PREVIEW_URL: previewUrl, // global preview URL
},
headHtmlSnippet: getManagerHeadHtml(configDir, process.env),
}),
template: require.resolve(`../templates/index.ejs`),
}),
new CaseSensitivePathsPlugin(),
new Dotenv({ silent: true }),
// graphql sources check process variable
new DefinePlugin({
'process.env': stringified,
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}),
// See https://github.com/graphql/graphql-language-service/issues/111#issuecomment-306723400
new ContextReplacementPlugin(/graphql-language-service-interface[/\\]dist/, /\.js$/),
new CoreJSUpgradeWebpackPlugin({ resolveFrom: __dirname }),
].filter(Boolean),
module: {
rules: [
babelLoader(babelOptions),
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
},
},
],
},
{
test: /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
loader: require.resolve('file-loader'),
query: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
{
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
loader: require.resolve('url-loader'),
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]',
},
},
],
},
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.json'],
modules: ['node_modules'].concat(raw.NODE_PATH || []),
alias: {
...themingPaths,
...uiPaths,
},
},
recordsPath: path.join(cacheDir, 'records.json'),
performance: {
hints: false,
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
},
};
};