-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
196 lines (186 loc) · 5.25 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const webpack = require('webpack');
module.exports = (env) => {
// style files regexes
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
const sassRegex = /\.(scss|sass)$/;
const sassModuleRegex = /\.module\.(scss|sass)$/;
const cssModuleLocalIdent = "[hash:base64:6]";
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: require.resolve("css-loader"),
options: {
url: false,
...cssOptions,
},
},
{
loader: require.resolve("postcss-loader"),
},
].filter(Boolean);
if (preProcessor) {
loaders.push({
loader: require.resolve(preProcessor),
});
}
return loaders;
};
return {
mode: "production",
performance: {
hints: false,
},
optimization: {
minimize: true
},
devtool: undefined,
context: path.resolve(__dirname, "src"),
entry: {
index: './library',
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js',
library: 'FlipNumbers',
libraryTarget: 'umd',
globalObject: 'this',
umdNamedDefine: true,
},
devServer: {
historyApiFallback: true,
hot: true,
compress: true
},
module: {
rules: [
{
test: /\.?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
plugins: ['lodash'],
presets: ["@babel/preset-env", "@babel/preset-react", { modules: false, targets: { node: 4 } }],
},
},
},
{
test: /\.(js|jsx|ts|tsx)$/,
use: {
loader: "ts-loader",
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true,
},
},
exclude: /(node_modules|bower_components)/,
},
{
test: cssRegex,
exclude: cssModuleRegex,
use: getStyleLoaders({
importLoaders: 1,
modules: {
compileType: "icss",
},
}),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
// Remove this when webpack adds a warning or an error for this.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
},
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
// using the extension .module.css
{
test: cssModuleRegex,
use: getStyleLoaders({
importLoaders: 1,
modules: {
compileType: "module",
localIdentName: cssModuleLocalIdent,
},
}),
},
// Opt-in support for SASS (using .scss or .sass extensions).
// By default we support SASS Modules with the
// extensions .module.scss or .module.sass
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
modules: {
compileType: "icss",
},
},
"sass-loader"
),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
// Remove this when webpack adds a warning or an error for this.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
{
test: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
modules: {
compileType: "module",
localIdentName: cssModuleLocalIdent,
},
},
"sass-loader"
),
}
],
},
plugins: [
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: "../tsconfig.json",
},
}),
new MiniCssExtractPlugin({
filename: "./FlipNumbers/styles.css",
})
].filter(function (plugin) { return plugin !== false; }),
resolve: {
alias: {
app: path.resolve(__dirname, "./src/"),
library: path.resolve(__dirname, "./src/library/"),
},
extensions: [".ts", ".tsx", ".js", ".jsx", ".css", ".scss"],
fallback: { timers: false },
},
externals: {
'react': {
'commonjs': 'react',
'commonjs2': 'react',
'amd': 'react',
// React dep should be available as window.React, not window.react
'root': 'React'
},
'react-dom': {
'commonjs': 'react-dom',
'commonjs2': 'react-dom',
'amd': 'react-dom',
'root': 'ReactDOM'
}
}
};
};