UNPKG

1.49 kBJavaScriptView Raw
1const path = require('path');
2
3const dir_js = path.resolve(__dirname, 'react_components');
4const dir_build = path.resolve(__dirname, 'build');
5const dir_dist = path.resolve(__dirname, 'dist');
6const dir_node_modules = path.resolve(__dirname, 'node_modules');
7
8const 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 // this to support both browser and Node.
16 // https://github.com/riversun/making-library-with-webpack#1-4publish-an-export-default-class-with-the-setting-library-name--class-name
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
53module.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};