-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·178 lines (169 loc) · 3.97 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
const path = require('path');
const pkg = require('./package.json');
var nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
process.env.NODE_ENV = 'production';
const isEnvProduction = process.env.NODE_ENV === 'production';
const isEnvDevelopment = process.env.NODE_ENV === 'development';
const jsConfig = {
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
devtool: isEnvProduction ? 'source-map' : 'cheap-module-source-map',
node: {
module: 'empty',
dgram: 'empty',
dns: 'mock',
fs: 'empty',
http2: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
},
entry: './src/index.js',
resolve: {
modules: [path.resolve('./node_modules'), path.resolve('./src')],
extensions: [
'.web.mjs',
'.mjs',
'.web.js',
'.js',
'.web.ts',
'.ts',
'.web.tsx',
'.tsx',
'.json',
'.web.jsx',
'.jsx',
]
},
optimization: {
minimizer: [
new TerserPlugin(),
],
},
plugins: [],
module: {
rules: [
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
}
const getStyleLoaders = () => [
isEnvProduction && {
loader: MiniCssExtractPlugin.loader,
},
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
sourceMap: isEnvProduction
}
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: isEnvProduction,
},
}
]
if (isEnvDevelopment) {
getStyleLoaders.push(require.resolve('style-loader'))
}
const cssConfig = {
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
node: {
module: 'empty',
dgram: 'empty',
dns: 'mock',
fs: 'empty',
http2: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
},
entry: {
fullViewLayout: './src/styles/FullViewLayout.scss',
compactLayout: './src/styles/CompactLayout.scss',
},
resolve: {
modules: [path.resolve('./node_modules'), path.resolve('./src')],
extensions: [
'.js',
'.jsx',
]
},
optimization: {
minimizer: [
// This is only used in production mode
new OptimizeCSSAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
},
canPrint: true
}),
],
},
plugins: [
isEnvProduction &&
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'dist/css/[name].css',
chunkFilename: 'dist/css/[name].css',
}),
],
module: {
rules: [
{
test: /\.(scss|sass)$/,
exclude: /\.module\.(scss|sass)$/,
use: getStyleLoaders(),
// 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,
},
]
}
}
// Bundle in commonjs format
const commonjsModule = {
...jsConfig,
externals: [
nodeExternals()
],
output: {
path: __dirname,
filename: pkg.main,
libraryTarget: 'commonjs2'
},
};
// Bundle in browser compatible format
const browserModule = {
...jsConfig,
output: {
path: __dirname,
filename: pkg.cdn,
library: 'Channelize',
libraryTarget: 'window'
}
};
// Bundle all styles in css files
const cssModule = {
...cssConfig,
output: {
path: __dirname,
filename: 'dist/[name].js',
libraryTarget: 'commonjs2'
}
};
module.exports = [commonjsModule, browserModule, cssModule];