-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.ts
108 lines (103 loc) · 2.69 KB
/
webpack.common.ts
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
import os from 'os';
import path from 'path';
import { Configuration } from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
const useExperimentalFeatures = process.env.CARBON_USE_EXPERIMENTAL_FEATURES === 'true';
const useBreakingChanges = process.env.CARBON_USE_BREAKING_CHANGES === 'true';
const replaceTable = {
componentsX: useExperimentalFeatures,
breakingChangesX: useBreakingChanges,
};
const common: Configuration = {
entry: {
playground: path.join(__dirname, 'src/client/playground/index.tsx'),
},
output: {
filename: '[name].bundle.js',
path: path.join(__dirname, 'dist'),
},
optimization: {
splitChunks: {
name: 'vendor',
chunks: 'initial',
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(tsx)?$/,
use: [
{ loader: 'cache-loader' },
{
loader: 'thread-loader',
options: {
workers: os.cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
happyPackMode: true,
},
},
],
},
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 2,
},
},
{
loader: 'sass-loader',
options: {
includePaths: [path.resolve(__dirname, '..', 'node_modules')],
data: `
$feature-flags: (
components-x: ${useExperimentalFeatures},
breaking-changes-x: ${useBreakingChanges},
grid: ${useExperimentalFeatures},
ui-shell: true,
);
`,
},
},
],
}),
},
{
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',
})),
},
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
new ExtractTextPlugin({
filename: 'styles.css',
}),
],
};
export default common;