1 | const path = require('path')
|
2 | const webpack = require('webpack')
|
3 | const ManifestPlugin = require('webpack-assets-manifest')
|
4 |
|
5 | const ENV = process.env.NODE_ENV
|
6 | const TARGET = process.env.GNOLL_TARGET
|
7 | const ASSETS_CACHING = process.env.GNOLL_ASSETS_CACHING
|
8 |
|
9 |
|
10 | const paths = require('../utils/paths')
|
11 | const getBabelConfig = require('../utils/getBabelConfig')
|
12 |
|
13 | const babelConfig = getBabelConfig()
|
14 |
|
15 | const STATIC_FILES_REGEXP = /\.(png|svg|jpg|jpeg|gif|webp|eot|ttf|woff|woff2|otf|mp4|ogg|webm|mp3)$/
|
16 |
|
17 | const entry = [path.resolve(paths.root, 'src/index.js')]
|
18 |
|
19 | const output = {
|
20 | path: path.join(paths.root, 'build'),
|
21 | filename: '[name].js',
|
22 | publicPath: '/'
|
23 | }
|
24 |
|
25 | const plugins = []
|
26 |
|
27 | if (TARGET === 'node' || TARGET === 'universal') {
|
28 | output.libraryTarget = 'commonjs'
|
29 | }
|
30 |
|
31 |
|
32 | if (TARGET === 'web' && ASSETS_CACHING) {
|
33 | output.filename = '[name].[chunkhash].js'
|
34 | plugins.push(
|
35 | new ManifestPlugin({ output: 'manifest.json', writeToDisk: true })
|
36 | )
|
37 | }
|
38 |
|
39 | if (TARGET === 'web' && ENV === 'production') {
|
40 | plugins.push(new webpack.HashedModuleIdsPlugin())
|
41 | }
|
42 |
|
43 | const rules = [
|
44 | {
|
45 | test: /\.jsx?$/,
|
46 | use: ['source-map-loader'],
|
47 | enforce: 'pre'
|
48 | },
|
49 | {
|
50 | test: /\.jsx?$/,
|
51 | include: [path.join(paths.root, 'src')],
|
52 | loader: 'babel-loader',
|
53 | options: {
|
54 | ...babelConfig,
|
55 | cacheDirectory: path.join(paths.cache, 'babel-loader')
|
56 | }
|
57 | },
|
58 | {
|
59 | test: STATIC_FILES_REGEXP,
|
60 | loader: 'file-loader',
|
61 | options: {
|
62 | emitFile: TARGET === 'web'
|
63 | }
|
64 | }
|
65 | ]
|
66 |
|
67 | module.exports = {
|
68 | entry,
|
69 | output,
|
70 | target: TARGET,
|
71 | mode: ENV === 'production' ? 'production' : 'development',
|
72 | plugins,
|
73 | module: {
|
74 | rules
|
75 | },
|
76 | resolve: {
|
77 | extensions: ['.js', '.jsx', '.json'],
|
78 | modules: [
|
79 | 'node_modules',
|
80 |
|
81 |
|
82 | path.resolve(__dirname, '..', 'node_modules')
|
83 | ]
|
84 | },
|
85 | resolveLoader: {
|
86 | modules: [
|
87 | 'node_modules',
|
88 |
|
89 |
|
90 | path.resolve(__dirname, '..', 'node_modules')
|
91 | ]
|
92 | },
|
93 | devtool: ENV !== 'production' ? 'cheap-module-source-map' : undefined
|
94 | }
|