-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.ts
executable file
·94 lines (90 loc) · 2.63 KB
/
webpack.config.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
import CopyPlugin from 'copy-webpack-plugin';
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import path from 'path';
import TerserPlugin from 'terser-webpack-plugin';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import webpack from 'webpack';
import nodeExternals from 'webpack-node-externals';
export const BASE_URL = 'src';
const MINIFIED_PATH = 'dist/umd';
const SASS_PATH = 'dist/sass';
export const CSS_PATH = 'dist/css';
const LIBRARY_NAME = 'webviewer-react-toolkit';
const miniCssExtractPlugin = new MiniCssExtractPlugin({ filename: `${CSS_PATH}/style.css` });
const config: webpack.Configuration = {
mode: 'production',
entry: [`./${BASE_URL}/index.ts`, `./${BASE_URL}/index.scss`],
output: {
path: path.resolve(__dirname),
filename: `${MINIFIED_PATH}/${LIBRARY_NAME}.min.js`,
},
externals: [nodeExternals()],
plugins: [
miniCssExtractPlugin as any,
new CopyPlugin([
{
from: `${BASE_URL}/styles/_variables.scss`,
to: `${SASS_PATH}/_variables.scss`,
},
{
from: `${BASE_URL}/styles/_mixins.scss`,
to: `${SASS_PATH}/_mixins.scss`,
},
{
from: `${BASE_URL}/styles/_breakpoints.scss`,
to: `${SASS_PATH}/_breakpoints.scss`,
},
]),
],
optimization: {
usedExports: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: { comparisons: false, inline: 2 },
mangle: { safari10: true },
output: { ascii_only: true },
toplevel: true,
},
parallel: true,
}),
new OptimizeCSSAssetsPlugin({}),
],
},
resolve: {
// Only add file types you want to resolve inline without extension.
extensions: ['.ts', '.tsx', '.scss', '.json'],
plugins: [
new TsconfigPathsPlugin({
configFile: './tsconfig.json',
baseUrl: BASE_URL,
}),
],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: { presets: ['@babel/preset-env', '@babel/preset-react'] },
},
{ loader: require.resolve('ts-loader'), options: { transpileOnly: true } },
],
},
{
test: /\.scss$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: require.resolve('css-loader') },
{ loader: require.resolve('postcss-loader') },
{ loader: require.resolve('sass-loader') },
],
},
],
},
};
export default config;