forked from carbon-design-system/carbon-components-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (98 loc) · 2.51 KB
/
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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const useExperimentalFeatures =
process.env.CARBON_USE_EXPERIMENTAL_FEATURES === 'true';
const useExternalCss =
process.env.CARBON_REACT_STORYBOOK_USE_EXTERNAL_CSS === 'true';
const useStyleSourceMap =
process.env.CARBON_REACT_STORYBOOK_USE_STYLE_SOURCEMAP === 'true';
const replaceTable = {
componentsX: useExperimentalFeatures,
};
const styleLoaders = [
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: useStyleSourceMap,
},
},
{
loader: 'postcss-loader',
options: {
plugins: () => [
require('autoprefixer')({
browsers: ['last 1 version', 'ie >= 11'],
}),
],
sourceMap: useStyleSourceMap,
},
},
{
loader: 'sass-loader',
options: {
includePaths: [path.resolve(__dirname, '..', 'node_modules')],
data: `
$feature-flags: (
components-x: ${useExperimentalFeatures},
grid: ${useExperimentalFeatures},
ui-shell: ${useExperimentalFeatures},
);
`,
sourceMap: useStyleSourceMap,
// Ref: webpack-contrib/sass-loader#272
outputStyle: useStyleSourceMap ? 'compressed' : 'expanded',
},
},
];
module.exports = {
module: {
rules: [
{
test: /\/FeatureFlags\.js$/,
loader: 'string-replace-loader',
options: {
multiple: Object.keys(replaceTable).map(key => ({
search: `export\\s+const\\s+${key}\\s*=\\s*false`,
replace: `export const ${key} = ${replaceTable[key]}`,
flags: 'i',
})),
},
},
{
test: /\-story\.jsx?$/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: {
prettierConfig: {
parser: 'babylon',
printWidth: 80,
tabWidth: 2,
bracketSpacing: true,
trailingComma: 'es5',
singleQuote: true,
},
},
},
],
enforce: 'pre',
},
{
test: /\.scss$/,
use: !useExternalCss
? [{ loader: 'style-loader' }, ...styleLoaders]
: ExtractTextPlugin.extract({
use: styleLoaders,
}),
},
],
},
plugins: !useExternalCss
? []
: [
new ExtractTextPlugin({
filename: '[name].[contenthash].css',
}),
],
};