Skip to content

Commit

Permalink
Speed webpack compilation (oppia#6751)
Browse files Browse the repository at this point in the history
* speed up webpack compilation

* compile webpack before running server

* add explaining comment

* add quicker compile to tests + formatting

* add typechecking

* dont specify files in tests

* add explaining comment

* use prod mode in backend test

* set DEV_MODE to true

* remove trailing space
  • Loading branch information
vojtechjelinek authored May 18, 2019
1 parent ea893be commit 33e6847
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 16 deletions.
19 changes: 17 additions & 2 deletions core/tests/karma.conf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var argv = require('yargs').argv;
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var path = require('path');
var generatedJs = 'third_party/generated/js/third_party.js';
if (argv.prodEnv) {
generatedJs = (
Expand Down Expand Up @@ -151,9 +153,22 @@ module.exports = function(config) {
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
use: [
'cache-loader',
'thread-loader',
{
loader: 'ts-loader',
options: {
// this is needed for thread-loader to work correctly
happyPackMode: true
}
}
]
}]
}
},
plugins: [
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true })
]
}
});
};
129 changes: 129 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
"ajv": "^6.10.0",
"babel-eslint": "^10.0.1",
"browserstack-local": "^1.3.7",
"cache-loader": "^3.0.1",
"clean-webpack-plugin": "^2.0.1",
"dotenv": "^7.0.0",
"enhanced-resolve": "^4.1.0",
"eslint": "^5.16.0",
"eslint-plugin-angular": "^4.0.0",
"eslint-plugin-html": "^5.0.3",
"fork-ts-checker-webpack-plugin": "^1.3.3",
"gulp": "^4.0.1",
"gulp-concat": "^2.6.1",
"htmllint": "^0.8.0",
Expand All @@ -65,6 +67,7 @@
"protractor-screenshot-reporter": "0.0.5",
"stylelint": "^10.0.1",
"stylelint-config-standard": "^18.3.0",
"thread-loader": "^2.1.2",
"ts-loader": "^5.4.4",
"typescript": "^3.4.5",
"uglify-js": "^3.5.8",
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_backend_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ echo "Compiling typescript..."
$NODE_MODULE_DIR/typescript/bin/tsc --project .

echo "Compiling webpack..."
$NODE_MODULE_DIR/webpack/bin/webpack.js --config webpack.dev.config.ts
$NODE_MODULE_DIR/webpack/bin/webpack.js --config webpack.prod.config.ts
$PYTHON_CMD scripts/build.py

$PYTHON_CMD scripts/backend_tests.py $@
Expand Down
5 changes: 4 additions & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,18 @@ rm assets/constants.js.bak

# Set up a local dev instance.
# TODO(sll): do this in a new shell.
echo Starting GAE development server
# To turn emailing on, add the option '--enable_sendmail=yes' and change the relevant
# settings in feconf.py. Be careful with this -- you do not want to spam people
# accidentally!

if ! [[ "$FORCE_PROD_MODE" == "True" ]]; then
($NODE_PATH/bin/node $NODE_MODULE_DIR/gulp/bin/gulp.js watch)&
# In prod mode webpack is launched through scripts/build.py
echo Compiling webpack...
$NODE_MODULE_DIR/webpack/bin/webpack.js --config webpack.dev.config.ts
($NODE_MODULE_DIR/webpack/bin/webpack.js --config webpack.dev.config.ts --watch)&
fi
echo Starting GAE development server
(python $GOOGLE_APP_ENGINE_HOME/dev_appserver.py $CLEAR_DATASTORE_ARG $ENABLE_CONSOLE_ARG --admin_host 0.0.0.0 --admin_port 8000 --host 0.0.0.0 --port 8181 --skip_sdk_update_check true app.yaml)&

# Wait for the servers to come up.
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

var CleanWebpackPlugin = require('clean-webpack-plugin');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var htmlMinifyConfig = {
Expand Down Expand Up @@ -352,5 +353,6 @@ module.exports = {
minify: htmlMinifyConfig,
inject: false
}),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true })
]
};
29 changes: 23 additions & 6 deletions webpack.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,29 @@ module.exports = {
entry: commonWebpackConfig.entries,
plugins: commonWebpackConfig.plugins,
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
}
]
rules: [{
test: /\.ts$/,
include: [
path.resolve(__dirname, 'core/templates/dev/head'),
path.resolve(__dirname, 'typings')
],
use: [
'cache-loader',
{
loader: 'thread-loader',
options: {
poolTimeout: Infinity,
}
},
{
loader: 'ts-loader',
options: {
// this is needed for thread-loader to work correctly
happyPackMode: true
}
}
]
}]
},
output: {
filename: '[name].bundle.js',
Expand Down
24 changes: 18 additions & 6 deletions webpack.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ module.exports = {
entry: commonWebpackConfig.entries,
plugins: commonWebpackConfig.plugins,
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
}
]
rules: [{
test: /\.ts$/,
include: [
path.resolve(__dirname, 'core/templates/dev/head'),
path.resolve(__dirname, 'typings')
],
use: [
'cache-loader',
'thread-loader',
{
loader: 'ts-loader',
options: {
// this is needed for thread-loader to work correctly
happyPackMode: true
}
}
]
}]
},
output: {
filename: '[name].[contenthash].bundle.js',
Expand Down

0 comments on commit 33e6847

Please sign in to comment.