-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.config.common.js
231 lines (224 loc) · 5.39 KB
/
webpack.config.common.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright © 2016 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
var webpack = require('webpack');
var path = require('path');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
var TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
// the clean options to use
let cleanOptions = {
verbose: true,
dry: false,
};
var mode = process.env.NODE_ENV || 'production';
const isModeProduction = (mode) => mode === 'production' || mode === 'non-optimized-production';
var plugins = [
new LodashModuleReplacementPlugin({
shorthands: true,
collections: true,
caching: true,
flattening: true,
}),
new CleanWebpackPlugin(cleanOptions),
new CaseSensitivePathsPlugin(),
// by default minify it.
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: isModeProduction(mode)
? JSON.stringify('production')
: JSON.stringify('development'),
},
}),
];
if (!isModeProduction(mode)) {
plugins.push(
new ForkTsCheckerWebpackPlugin({
tsconfig: __dirname + '/tsconfig.json',
tslint: __dirname + '/tslint.json',
tslintAutoFix: true,
// watch: ["./app/cdap"], // optional but improves performance (less stat calls)
memoryLimit: 4096,
})
);
}
const loaderExclude = [
/node_modules/,
/packaged\/public\/dist/,
/packaged\/public\/cdap_dist/,
/packaged\/public\/common_dist/,
/lib/,
];
var rules = [
{
test: /\.s?css$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.ya?ml$/,
use: 'yml-loader',
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
options: {
fix: true,
},
exclude: loaderExclude,
include: [path.join(__dirname, 'app'), path.join(__dirname, '.storybook')],
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: loaderExclude,
},
{
test: /\.tsx?$/,
use: [
'babel-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
exclude: loaderExclude,
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff',
},
},
],
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'url-loader',
},
{
test: /\.svg/,
use: [
{
loader: 'svg-sprite-loader',
},
],
},
];
var webpackConfig = {
mode: isModeProduction(mode) ? 'production' : 'development',
context: __dirname + '/app/common',
optimization: {
splitChunks: {
minChunks: Infinity,
},
},
entry: {
'common-new': ['./cask-shared-components.js'],
'common-lib-new': [
'@babel/polyfill',
'classnames',
'reactstrap',
'i18n-react',
'sockjs-client',
'react-dropzone',
'react-redux',
'svg4everybody',
'numeral',
],
},
module: {
rules,
},
stats: {
assets: false,
children: false,
chunkGroups: false,
chunkModules: false,
chunkOrigins: false,
chunks: false,
modules: false,
},
output: {
filename: '[name].js',
chunkFilename: '[name].[chunkhash].js',
path: __dirname + '/packaged/public/common_dist',
library: 'CaskCommon',
libraryTarget: 'umd',
publicPath: '/common_assets/',
globalObject: 'window',
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
'react-addons-css-transition-group': {
commonjs: 'react-addons-css-transition-group',
commonjs2: 'react-addons-css-transition-group',
amd: 'react-addons-css-transition-group',
root: ['React', 'addons', 'CSSTransitionGroup'],
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
components: __dirname + '/app/cdap/components',
services: __dirname + '/app/cdap/services',
api: __dirname + '/app/cdap/api',
wrangler: __dirname + '/app/wrangler',
styles: __dirname + '/app/cdap/styles',
'@cdap-ui': __dirname + '/app/cdap',
},
},
plugins,
};
if (!isModeProduction(mode)) {
webpackConfig.devtool = 'source-maps';
}
if (isModeProduction(mode)) {
webpackConfig.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
cache: false,
parallel: true,
sourceMap: true,
extractComments: true,
output: {
comments: false,
},
ie8: false,
safari10: false,
},
}),
];
}
module.exports = webpackConfig;