UNPKG

1.7 kBJavaScriptView Raw
1const path = require('path');
2const HtmlWebpackPlugin = require('html-webpack-plugin');
3const webpack = require('webpack');
4
5module.exports = ({ context, options }) => {
6 const packageJSON = require(path.resolve(context, './package.json')); // eslint-disable-line
7 return {
8 context,
9 entry: {
10 [path
11 .basename(options.entry)
12 .split('.')
13 .slice(0, -1)
14 .join('.')]: options.entry,
15 },
16 module: {
17 rules: [
18 {
19 test: /\.svg$/,
20 loader: 'svg-react-loader',
21 options: {
22 name: 'SVGReactComponent',
23 },
24 },
25 {
26 test: /\.(png|jpe?g|gif|woff|woff2|ttf|otf)$/,
27 loader: 'url-loader',
28 options: {
29 limit: 10240,
30 },
31 },
32 ],
33 },
34 output: {
35 path: path.resolve(context, options.outputPath),
36 filename: '[name].js',
37 chunkFilename: '[name].[chunkhash].js',
38 crossOriginLoading: 'anonymous',
39 },
40 plugins: [
41 new webpack.ContextReplacementPlugin(/moment[\\/]locale$/, /^\.\/(en|zh-cn)/),
42 new webpack.DefinePlugin({
43 __VERSION__: JSON.stringify(packageJSON.version || '0.0.1'),
44 }),
45 new HtmlWebpackPlugin({
46 template: './src/index.html',
47 }),
48 ],
49 resolve: {
50 modules: ['node_modules'],
51 extensions: ['.js', '.jsx', '.json'],
52 },
53 target: 'web',
54 // Some libraries import Node modules but don't use them in the browser.
55 // Tell Webpack to provide empty mocks for them so importing them works.
56 node: {
57 dgram: 'empty',
58 fs: 'empty',
59 net: 'empty',
60 tls: 'empty',
61 child_process: 'empty',
62 },
63 };
64};