webpack.common.config.js 6.49 KB
Newer Older
1 2 3 4
/* eslint-env node */

'use strict';

5 6 7
var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
8
var StringReplace = require('string-replace-webpack-plugin');
9

10 11 12 13 14
var namespacedRequireFiles = [
    path.resolve(__dirname, 'common/static/common/js/components/views/feedback_notification.js'),
    path.resolve(__dirname, 'common/static/common/js/components/views/feedback.js')
];

15
module.exports = {
16 17 18
    context: __dirname,

    entry: {
19
        // Studio
20
        AssetsPage: './node_modules/@edx/studio-frontend/src/index.jsx',
21 22
        Import: './cms/static/js/features/import/factories/import.js',
        StudioIndex: './cms/static/js/features_jsx/studio/index.jsx',
23
        AccessibilityPage: './node_modules/@edx/studio-frontend/src/accessibilityIndex.jsx',
24

25
        // LMS
26
        SingleSupportForm: './lms/static/support/jsx/single_support_form.jsx',
27
        AlertStatusBar: './lms/static/js/accessible_components/StatusBarAlert.jsx',
28

29
        // Features
30
        CourseGoals: './openedx/features/course_experience/static/course_experience/js/CourseGoals.js',
31
        CourseHome: './openedx/features/course_experience/static/course_experience/js/CourseHome.js',
32
        CourseOutline: './openedx/features/course_experience/static/course_experience/js/CourseOutline.js',
33
        CourseSock: './openedx/features/course_experience/static/course_experience/js/CourseSock.js',
34
        CourseTalkReviews: './openedx/features/course_experience/static/course_experience/js/CourseTalkReviews.js',
35
        Currency: './openedx/features/course_experience/static/course_experience/js/currency.js',
36
        Enrollment: './openedx/features/course_experience/static/course_experience/js/Enrollment.js',
37
        LatestUpdate: './openedx/features/course_experience/static/course_experience/js/LatestUpdate.js',
38 39 40 41
        WelcomeMessage: './openedx/features/course_experience/static/course_experience/js/WelcomeMessage.js',

        // Common
        ReactRenderer: './common/static/js/src/ReactRenderer.jsx'
42 43 44 45 46 47 48 49 50 51 52
    },

    output: {
        path: path.resolve(__dirname, 'common/static/bundles'),
        libraryTarget: 'window'
    },

    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.NamedModulesPlugin(),
        new BundleTracker({
53
            path: process.env.STATIC_ROOT_CMS,
54
            filename: 'webpack-stats.json'
55 56 57 58 59 60 61 62 63
        }),
        new BundleTracker({
            path: process.env.STATIC_ROOT_LMS,
            filename: 'webpack-stats.json'
        }),
        new webpack.ProvidePlugin({
            _: 'underscore',
            $: 'jquery',
            jQuery: 'jquery',
64
            'window.jQuery': 'jquery'
65 66 67 68 69 70 71 72 73 74 75
        }),

        // Note: Until karma-webpack releases v3, it doesn't play well with
        // the CommonsChunkPlugin. We have a kludge in karma.common.conf.js
        // that dynamically removes this plugin from webpack config when
        // running those tests (the details are in that file). This is a
        // recommended workaround, as this plugin is just an optimization. But
        // because of this, we really don't want to get too fancy with how we
        // invoke this plugin until we can upgrade karma-webpack.
        new webpack.optimize.CommonsChunkPlugin({
            // If the value below changes, update the render_bundle call in
76
            // common/djangoapps/pipeline_mako/templates/static_content.html
77 78 79
            name: 'commons',
            filename: 'commons.js',
            minChunks: 2
80
        })
Brian Jacobel committed
81
    ],
82 83 84 85

    module: {
        rules: [
            {
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                test: namespacedRequireFiles,
                loader: StringReplace.replace(
                    ['babel-loader'],
                    {
                        replacements: [
                            {
                                pattern: /\(function ?\(define\) ?\{/,
                                replacement: function() { return ''; }
                            },
                            {
                                pattern: /\}\)\.call\(this, define \|\| RequireJS\.define\);/,
                                replacement: function() { return ''; }
                            }
                        ]
                    }
                )
            },
            {
104
                test: /\.(js|jsx)$/,
105 106 107 108
                exclude: [
                    /node_modules/,
                    namespacedRequireFiles
                ],
109
                use: 'babel-loader'
110 111
            },
            {
112 113 114 115 116 117 118 119
                test: /\.(js|jsx)$/,
                include: [
                    /studio-frontend/,
                    /paragon/
                ],
                use: 'babel-loader'
            },
            {
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
                test: /\.coffee$/,
                exclude: /node_modules/,
                use: 'coffee-loader'
            },
            {
                test: /\.underscore$/,
                use: 'raw-loader'
            },
            {
                // This file is used by both RequireJS and Webpack and depends on window globals
                // This is a dirty hack and shouldn't be replicated for other files.
                test: path.resolve(__dirname, 'cms/static/cms/js/main.js'),
                use: {
                    loader: 'imports-loader',
                    options: {
135 136
                        AjaxPrefix:
                            'exports-loader?this.AjaxPrefix!../../../../common/static/coffee/src/ajax_prefix.coffee'
137 138
                    }
                }
139 140 141 142
            },
            {
                test: /\.(woff2?|ttf|svg|eot)(\?v=\d+\.\d+\.\d+)?$/,
                loader: 'file-loader'
143 144 145 146 147
            }
        ]
    },

    resolve: {
148
        extensions: ['.js', '.jsx', '.json', '.coffee'],
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        alias: {
            'edx-ui-toolkit': 'edx-ui-toolkit/src/',  // @TODO: some paths in toolkit are not valid relative paths
            'jquery.ui': 'jQuery-File-Upload/js/vendor/jquery.ui.widget.js',
            jquery: 'jquery/src/jquery'  // Use the non-dist form of jQuery for better debugging + optimization
        },
        modules: [
            'node_modules',
            'common/static/js/vendor/'
        ]
    },

    resolveLoader: {
        alias: {
            text: 'raw-loader'  // Compatibility with RequireJSText's text! loader, uses raw-loader under the hood
        }
    },

    externals: {
167
        backbone: 'Backbone',
168
        coursetalk: 'CourseTalk',
169 170 171 172 173
        gettext: 'gettext',
        jquery: 'jQuery',
        logger: 'Logger',
        underscore: '_',
        URI: 'URI'
174 175 176 177
    },

    watchOptions: {
        poll: true
178
    }
Brian Jacobel committed
179
};