% if blocks.get('children'):
    @@ -163,3 +159,7 @@ from openedx.core.djangolib.markup import HTML, Text <%static:require_module_async module_name="js/dateutil_factory" class_name="DateUtilFactory"> DateUtilFactory.transform('.localized-datetime'); + +<%static:webpack entry="CourseOutline"> + new CourseOutline('.block-tree'); + diff --git a/package.json b/package.json index 50e4eac706..0f5fb8b8c7 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,13 @@ "underscore.string": "~3.3.4" }, "devDependencies": { + "babel-core": "^6.23.0", + "babel-loader": "^6.4.0", + "babel-plugin-react": "^1.0.0", + "babel-plugin-transform-object-rest-spread": "^6.23.0", + "babel-polyfill": "^6.23.0", + "babel-preset-env": "^1.2.1", + "babel-preset-react": "^6.23.0", "edx-custom-a11y-rules": "0.1.3", "eslint-config-edx": "^2.0.0", "eslint-config-edx-es5": "^2.0.0", @@ -38,6 +45,8 @@ "pa11y-reporter-json-oldnode": "1.0.0", "plato": "1.2.2", "sinon": "1.17.3 || >1.17.4 <2.0.0", - "squirejs": "^0.1.0" + "squirejs": "^0.1.0", + "webpack": "^2.2.1", + "webpack-bundle-tracker": "^0.2.0" } } diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 188b95a86e..5c37f6e36d 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -115,6 +115,7 @@ xmltodict==0.4.1 django-ratelimit-backend==1.0 unicodecsv==0.9.4 django-require==1.0.11 +django-webpack-loader==0.4.1 pyuca==1.1 wrapt==1.10.5 zendesk==1.1.1 diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000000..9a63338265 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,58 @@ +const path = require('path'); +const webpack = require('webpack'); +const BundleTracker = require('webpack-bundle-tracker'); + +const isProd = process.env.NODE_ENV === 'production'; + +const wpconfig = { + context: __dirname, + + entry: { + CourseOutline: './openedx/features/course_experience/static/course_experience/js/CourseOutline.js', + }, + + output: { + path: path.resolve(__dirname, 'common/static/bundles'), + filename: '[name]-[hash].js', + libraryTarget: 'window', + }, + + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + new webpack.NamedModulesPlugin(), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), + }), + new webpack.LoaderOptionsPlugin({ + debug: !isProd, + }), + new BundleTracker({ + filename: './webpack-stats.json' + }), + ], + + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: 'babel-loader', + }, + ], + }, + resolve: { + extensions: ['.js', '.json'], + } +}; + +if (isProd) { + wpconfig.plugins = [ + new webpack.LoaderOptionsPlugin({ + minimize: true, + }), + new webpack.optimize.UglifyJsPlugin(), + ...wpconfig.plugins, + ]; +} + +module.exports = wpconfig;