-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
157 lines (151 loc) · 4.56 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
const path = require('path');
const sass = require('node-sass');
const fibers = require('fibers');
const postcssPresetEnv = require('postcss-preset-env');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const WebpackDeleteAfterEmit = require('webpack-delete-after-emit');
const devMode = process.env.NODE_ENV !== 'production';
const { webpackBundles } = require('./config');
const cssPackageBundler = () =>
webpackBundles.packagesList.map(pkg => {
const pkgPath = pkg.startsWith('and')
? `./packages/${pkg}`
: `./packages/and-${pkg}`;
const filename = `and.${pkg}`;
return {
mode: 'production',
entry: {
[filename]: path.resolve(__dirname, `${pkgPath}/${pkg}.scss`)
},
output: {
path: path.resolve(__dirname, `${pkgPath}/dist/`)
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [postcssPresetEnv()],
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
includePaths: [
path.join(__dirname, 'node_modules/normalize-scss/sass')
],
implementation: sass,
fiber: fibers,
sourceMap: true,
functions: {
'get($keys)': mapJsVarsToSass
}
}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].css',
chunkFilename: devMode ? '[id].css' : '[name].css'
}),
// new OptimizeCSSAssetsPlugin({
// cssProcessorOptions: {
// map: { inline: false } // generate sourcemap use an external file
// }
// })
new WebpackDeleteAfterEmit({ globs: ['*.js*'] })
]
};
});
const componentPackageBundler = () =>
webpackBundles.componentsList.map(pkg => {
const pkgPath = `./components/${pkg}`;
const pkgName = pkg.charAt(0).toUpperCase() + pkg.slice(1);
const libName = `And${pkgName}`;
return {
mode: 'production',
entry: {
[libName]: `${pkgPath}/index.jsx`
},
output: {
path: path.resolve(__dirname, `${pkgPath}/dist/`),
filename: '[name].js',
library: libName,
libraryTarget: 'umd',
publicPath: '/dist/',
umdNamedDefine: true
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
rootMode: 'upward',
sourceMaps: true
}
}
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [new CleanWebpackPlugin()],
resolve: {
// these alias are only used by the packages side the components folder.
// don't include packages in next-client folder.
alias: {
$config: path.resolve(__dirname, 'config'),
$packages: path.resolve(__dirname, 'packages'),
'@dl': path.resolve(__dirname, './node_modules/@dl'),
react: path.resolve(__dirname, './node_modules/react'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom')
}
},
externals: {
React: {
commonjs: 'react',
commonjs2: 'react',
amd: 'React',
root: 'React'
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'ReactDOM',
root: 'ReactDOM'
},
[`@dl/${pkg}`]: {
commonjs: `@dl/${pkg}`,
commonjs2: `@dl/${pkg}`,
amd: `@dl/${pkg}`,
root: `@dl/${pkg}`
}
}
};
});
module.exports = [...cssPackageBundler(), ...componentPackageBundler()];