-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
87 lines (81 loc) · 1.87 KB
/
webpack.config.babel.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
const { resolve } = require('path');
const { name } = require('./package.json');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const isDemo = process.env.REACT_DEMO && process.env.REACT_DEMO !== 'false';
const PROJECT_PATH = __dirname;
const inProject = (...args) => resolve(PROJECT_PATH, ...args);
const inSrc = inProject.bind(null, 'src');
const inTest = inProject.bind(null, 'test');
const inDemo = inProject.bind(null, 'demo');
const srcDir = inSrc();
const testDir = inTest();
const demoDir = inDemo();
module.exports = (webpackEnv = {}) => {
const { minify } = webpackEnv;
const config = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
include: [srcDir, testDir, demoDir],
loader: 'babel-loader',
options: { cacheDirectory: true },
},
],
},
resolve: {
modules: [srcDir, 'node_modules'],
extensions: ['.js'],
alias: {
// fix issues when using `npm link` or `yarn link`
'styled-components': resolve('./node_modules/styled-components'),
react: resolve('./node_modules/react'),
},
},
resolveLoader: {
moduleExtensions: ['-loader'],
},
mode: process.env.NODE_ENV,
optimization: {
minimize: !!minify,
},
devServer: {
contentBase: demoDir,
port: 3000,
},
};
if (isDemo) {
config.entry = './demo';
config.output = {
filename: 'bundle.js',
path: resolve(__dirname, 'demo'),
};
config.module.rules.push(
{
test: /\.scss$/,
include: demoDir,
use: ['style', 'css', 'postcss', 'sass'],
},
{
test: /\.es$/,
include: demoDir,
use: ['raw'],
},
);
}
else {
config.entry = './src';
config.output = {
filename: `${name}${minify ? '.min' : ''}.js`,
path: resolve(__dirname, 'dist'),
library: name,
libraryTarget: 'umd',
};
config.externals = {
react: 'React',
'react-dom': 'ReactDom',
};
}
return config;
};