webpack.config.dev.js 3.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';

const resolve = require('resolve');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');

const getClientEnvironment = require('./env');
const paths = require('./paths');

const publicPath = './';
const publicUrl = '.';
const env = getClientEnvironment(publicUrl);

const config = {
    mode: 'development',
    devtool: 'cheap-module-source-map',
    entry: [ paths.appIndexJs ],
    output: {
        path: paths.appBuild,
        pathinfo: true,
        filename: 'static/js/bundle.js',
        chunkFilename: 'static/js/[name].chunk.js',
        publicPath: publicPath,
    },
    optimization: { minimize: false },
    resolve: {
Lijiaoa's avatar
Lijiaoa committed
30
31
32
33
34
35
36
37
        modules: [ 'node_modules', 'src' ],
        alias: { 
            '@': paths.appSrc,
            '@components': `${paths.appSrc}/components`,
            '@static': `${paths.appSrc}/static`,
            '@style': `${paths.appSrc}/static/style`,
            '@model': `${paths.appSrc}/static/model`
        },
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
        extensions: paths.moduleFileExtensions.map(ext => `.${ext}`),
    },
    module: {
        strictExportPresence: true,
        rules: [
            {
                oneOf: [
                    {
                        test: [ /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/ ],
                        loader: require.resolve('url-loader'),
                        options: { limit: 10000, name: 'static/media/[name].[hash:8].[ext]' },
                    },
                    {
                        test: /\.(js|mjs|jsx|ts|tsx)$/,
                        include: paths.appSrc,
                        loader: require.resolve('babel-loader'),
                        options: { cacheDirectory: true, cacheCompression: false, compact: false },
                    },
                    {
                        test: /\.css$/,
                        use: [
                            require.resolve('style-loader'),
                            require.resolve('css-loader'),
                        ],
                        sideEffects: true,
                    },
                    {
                        test: /\.(scss|sass)$/,
                        use: [
                            require.resolve('style-loader'),
                            require.resolve('css-loader'),
                            require.resolve('sass-loader'),
                        ],
                        sideEffects: true,
                    },
                    {
                        loader: require.resolve('file-loader'),
                        exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
                        options: { name: 'static/media/[name].[hash:8].[ext]' },
                    },
                ],
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({ inject: true, template: paths.appHtml }),
        new MonacoWebpackPlugin({ languages: [ 'json' ] }),
        new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
        new ModuleNotFoundPlugin(paths.appPath),
    ],
    performance: { hints: false },
}

module.exports = () => config;