1 | const path = require('path');
|
2 | const webpack = require('webpack');
|
3 | const copyWebpackPlugin = require('copy-webpack-plugin');
|
4 |
|
5 | const config = {
|
6 | entry: {
|
7 | index: [
|
8 | 'babel-polyfill',
|
9 | 'react-hot-loader/patch',
|
10 | 'webpack-hot-middleware/client?noInfo=false',
|
11 | path.resolve(__dirname, "./lib/entry.index.js")
|
12 | ]
|
13 | },
|
14 | output: {
|
15 | path: path.resolve(__dirname, "theme/static"),
|
16 | filename: "[name].js"
|
17 | },
|
18 | resolve: {
|
19 | extensions: [".js", ".json", ".jsx", ".css"],
|
20 | },
|
21 |
|
22 | module: {
|
23 | rules: [
|
24 | {
|
25 | test: /\.jsx?$/,
|
26 | exclude: [
|
27 | path.resolve(process.cwd(), 'node_modules'),
|
28 | ],
|
29 | use: {
|
30 | loader: 'babel-loader',
|
31 | options: {
|
32 | presets: [
|
33 | ["es2015", {"modules": false}],
|
34 |
|
35 | "stage-0",
|
36 | "react"
|
37 |
|
38 | ],
|
39 | plugins: [
|
40 | "react-hot-loader/babel",
|
41 |
|
42 | ["import", { "libraryName": "antd", "style": "css" }]
|
43 |
|
44 | ]
|
45 | }
|
46 | }
|
47 | },
|
48 | {
|
49 | test: /\.css$/,
|
50 | use: [ 'style-loader', 'css-loader' ]
|
51 | },
|
52 | {
|
53 | test: /\.md$/,
|
54 | use: ['babel-loader', path.resolve(__dirname, 'lib/md-loader.js') ]
|
55 | },
|
56 | {
|
57 | test: /\.less$/,
|
58 | use: [{
|
59 | loader: "style-loader"
|
60 | }, {
|
61 | loader: "css-loader"
|
62 | }, {
|
63 | loader: "less-loader"
|
64 | }]
|
65 | }
|
66 | ],
|
67 | },
|
68 |
|
69 | devtool: "source-map",
|
70 |
|
71 | plugins: [
|
72 | new webpack.HotModuleReplacementPlugin()
|
73 |
|
74 |
|
75 |
|
76 | ]
|
77 | }
|
78 |
|
79 | module.exports = (isProduction = false) => {
|
80 | if (isProduction) {
|
81 | process.env.NODE_ENV = 'production';
|
82 | delete config.devtool;
|
83 |
|
84 | config.plugins = config.plugins.concat([
|
85 | new webpack.optimize.UglifyJsPlugin({
|
86 | compress: {
|
87 | warnings: false
|
88 | },
|
89 | comments: false
|
90 | }),
|
91 | new copyWebpackPlugin([
|
92 | {from: path.resolve(__dirname, './theme/static'), to: path.resolve(process.cwd(), './site')}
|
93 | ])
|
94 | ]);
|
95 | }
|
96 |
|
97 | return config;
|
98 | };
|