1 | const path = require('path');
|
2 |
|
3 | const dir_js = path.resolve(__dirname, 'react_components');
|
4 | const dir_build = path.resolve(__dirname, 'build');
|
5 | const dir_dist = path.resolve(__dirname, 'dist');
|
6 | const dir_node_modules = path.resolve(__dirname, 'node_modules');
|
7 |
|
8 | const config = {
|
9 | entry: path.resolve(dir_js, 'index.js'),
|
10 | output: {
|
11 | path: dir_build,
|
12 | library: 'ReactPaginate',
|
13 | filename: 'react-paginate.js',
|
14 | libraryTarget: 'umd',
|
15 |
|
16 |
|
17 | globalObject: 'this',
|
18 | },
|
19 | devServer: {
|
20 | contentBase: dir_build,
|
21 | },
|
22 | module: {
|
23 | rules: [
|
24 | {
|
25 | use: 'react-hot-loader/webpack',
|
26 | test: dir_js,
|
27 | exclude: dir_node_modules,
|
28 | },
|
29 | {
|
30 | use: 'babel-loader',
|
31 | test: dir_js,
|
32 | exclude: dir_node_modules,
|
33 | },
|
34 | ],
|
35 | },
|
36 | externals: [
|
37 | {
|
38 | react: {
|
39 | root: 'React',
|
40 | amd: 'react',
|
41 | commonjs: 'react',
|
42 | commonjs2: 'react',
|
43 | },
|
44 | },
|
45 | ],
|
46 | stats: {
|
47 | colors: true,
|
48 | },
|
49 | devtool: 'source-map',
|
50 | mode: 'development',
|
51 | };
|
52 |
|
53 | module.exports = (env, argv) => {
|
54 | if (argv.mode === 'production') {
|
55 | config.mode = 'production';
|
56 | config.output.path = dir_dist;
|
57 | config.module.rules = config.module.rules.filter(
|
58 | (rule) => rule.use !== 'react-hot-loader/webpack'
|
59 | );
|
60 | }
|
61 | return config;
|
62 | };
|