-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
129 lines (124 loc) · 3.04 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
const webpack = require('webpack');
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const fs = require('fs');
const appDirectory = fs.realpathSync(process.cwd());
// Gets absolute path of file within app directory
const resolveAppPath = (relativePath) => path.resolve(appDirectory, relativePath);
// Host
const host = process.env.HOST || 'localhost';
const env = process.env.NODE_ENV || 'development';
module.exports = {
mode: env === 'production' ? 'production' : 'development',
context: __dirname,
entry: {
lib: path.join(__dirname, 'src', 'index.ts'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
library: 'ui',
libraryTarget: 'umd',
umdNamedDefine: true,
},
devtool: 'source-map',
devServer: {
host: '0.0.0.0',
port: 9000,
},
resolve: {
extensions: [
'.js',
'.jsx',
'.json',
'.ts',
'.tsx',
'less',
'scss',
'svg',
'woff',
'ttf',
'eot',
],
},
module: {
rules: [
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /(node_modules)/,
use: [{ loader: 'babel-loader' }],
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
{
// Preprocess our own .css files
// This is the place to add your own loaders (e.g. sass/less etc.)
// for a list of loaders, see https://webpack.js.org/loaders/#styling
test: /\.css$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'less-loader', 'sass-loader'],
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
},
],
},
{
test: /\.(sass|scss)$/,
use: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: [path.resolve(__dirname, 'node_modules')],
},
},
},
],
},
{
// Preprocess 3rd party .css files located in node_modules
test: /\.css$/,
include: /node_modules/,
use: ['style-loader', 'css-loader'],
},
],
},
externals: {
'styled-components': {
commonjs: 'styled-components',
commonjs2: 'styled-components',
amd: 'styled-components',
},
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom',
},
},
plugins: [
new CopyWebpackPlugin({ patterns: [{ from: 'src/theme/kit.css', to: '' }] }),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
optimization: {
minimize: false,
},
};