Skip to content

Commit 5ba4074

Browse files
committed
Don't transpile in development mode.
1 parent f8cf5a8 commit 5ba4074

4 files changed

Lines changed: 72 additions & 47 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test-jest": "kolibri-tools test --config ./jest.conf.js",
1313
"test-jest-cov": "yarn run test-jest --coverage",
1414
"coverage": "yarn run test-jest-cov",
15-
"build": "yarn run hashi-build && kolibri-tools build prod --file ./build_tools/build_plugins.txt",
15+
"build": "yarn run hashi-build && kolibri-tools build prod --file ./build_tools/build_plugins.txt --transpile",
1616
"makemessages": "kolibri-tools i18n-extract-messages --pluginFile ./build_tools/build_plugins.txt",
1717
"createprofiles": "kolibri-tools i18n-profile --pluginFile ./build_tools/build_plugins.txt --output-file ./kolibri/locale/en/LC_MESSAGES/profiles/strings.csv",
1818
"transfercontext": "kolibri-tools i18n-transfer-context --pluginFile ./build_tools/build_plugins.txt",
@@ -25,7 +25,7 @@
2525
"devserver-warn": "run-p python-devserver lint-frontend:watch hashi-dev watch",
2626
"devserver-hot": "run-p python-devserver lint-frontend:watch:format hashi-dev watch-hot",
2727
"devserver-hot-warn": "run-p python-devserver lint-frontend:watch hashi-dev watch-hot",
28-
"bundle-stats": "kolibri-tools build stats --file ./build_tools/build_plugins.txt",
28+
"bundle-stats": "kolibri-tools build stats --file ./build_tools/build_plugins.txt --transpile",
2929
"clean": "kolibri-tools build clean --file ./build_tools/build_plugins.txt",
3030
"preinstall": "node ./packages/kolibri-tools/lib/npm_deprecation_warning.js",
3131
"lint-frontend": "kolibri-tools lint --pattern '{kolibri*/**/assets,packages,build_tools}/**/*.{js,vue,scss,less,css}' --ignore '**/dist/**,**/node_modules/**,**/static/**,**/kolibri-core-for-export/**'",

packages/kolibri-tools/lib/cli.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ program
5858
.option('--host <host>', 'Set a host to serve devserver', String, '0.0.0.0')
5959
.option('--json', 'Output webpack stats in JSON format - only works in prod mode', false)
6060
.option('--cache', 'Use cache in webpack', false)
61+
.option('--transpile', 'Transpile code using Babel', false)
6162
.action(function(mode, options) {
6263
const buildLogging = logger.getLogger('Kolibri Build');
6364
const modes = {
@@ -122,6 +123,7 @@ program
122123
port: options.port,
123124
mode: webpackMode,
124125
cache: options.cache,
126+
transpile: options.transpile,
125127
};
126128

127129
const webpackConfig = require('./webpack.config.plugin');
@@ -136,8 +138,19 @@ program
136138

137139
const compiler = webpack(webpackArray);
138140

141+
let start;
142+
143+
compiler.hooks.run.tap('Kolibri', () => {
144+
start = new Date();
145+
});
146+
147+
compiler.hooks.watchRun.tap('Kolibri', () => {
148+
start = new Date();
149+
});
150+
139151
compiler.hooks.done.tap('Kolibri', () => {
140-
buildLogging.info('Build complete');
152+
const time = new Date() - start;
153+
buildLogging.info(`Build complete in ${time / 1000} seconds`);
141154
});
142155

143156
if (mode === modes.DEV) {

packages/kolibri-tools/lib/webpack.config.base.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
55
const TerserPlugin = require('terser-webpack-plugin');
66
const webpack = require('webpack');
77

8-
module.exports = ({ mode = 'development', hot = false, cache = false } = {}) => {
8+
module.exports = ({ mode = 'development', hot = false, cache = false, transpile = false } = {}) => {
99
const production = mode === 'production';
1010

1111
// Have to pass this option to prevent complaints about empty exports:
@@ -34,6 +34,51 @@ module.exports = ({ mode = 'development', hot = false, cache = false } = {}) =>
3434
// for scss blocks
3535
const sassLoaders = [cssInsertionLoader, cssLoader, postCSSLoader, 'sass-loader'];
3636

37+
const rules = [
38+
// Transpilation and code loading rules
39+
{
40+
test: /\.vue$/,
41+
loader: 'vue-loader',
42+
options: {
43+
compilerOptions: {
44+
preserveWhitespace: false,
45+
},
46+
},
47+
},
48+
{
49+
test: /\.css$/,
50+
use: [cssInsertionLoader, cssLoader, postCSSLoader],
51+
},
52+
{
53+
test: /\.s[a|c]ss$/,
54+
use: sassLoaders,
55+
},
56+
{
57+
test: /\.(png|jpe?g|gif|svg|eot|woff|ttf|woff2)$/,
58+
type: 'asset',
59+
generator: {
60+
filename: '[name]-[contenthash][ext]',
61+
},
62+
parser: {
63+
dataUrlCondition: {
64+
maxSize: 10000,
65+
},
66+
},
67+
},
68+
];
69+
70+
if (transpile) {
71+
rules.push({
72+
test: /\.js$/,
73+
loader: 'babel-loader',
74+
exclude: { and: [/(node_modules\/vue|dist|core-js)/, { not: [/\.(esm\.js|mjs)$/] }] },
75+
options: {
76+
cacheDirectory: cache,
77+
cacheCompression: false,
78+
},
79+
});
80+
}
81+
3782
return {
3883
target: 'browserslist',
3984
mode,
@@ -45,47 +90,7 @@ module.exports = ({ mode = 'development', hot = false, cache = false } = {}) =>
4590
},
4691
},
4792
module: {
48-
rules: [
49-
// Transpilation and code loading rules
50-
{
51-
test: /\.vue$/,
52-
loader: 'vue-loader',
53-
options: {
54-
compilerOptions: {
55-
preserveWhitespace: false,
56-
},
57-
},
58-
},
59-
{
60-
test: /\.js$/,
61-
loader: 'babel-loader',
62-
exclude: { and: [/(node_modules\/vue|dist|core-js)/, { not: [/\.(esm\.js|mjs)$/] }] },
63-
options: {
64-
cacheDirectory: cache,
65-
cacheCompression: false,
66-
},
67-
},
68-
{
69-
test: /\.css$/,
70-
use: [cssInsertionLoader, cssLoader, postCSSLoader],
71-
},
72-
{
73-
test: /\.s[a|c]ss$/,
74-
use: sassLoaders,
75-
},
76-
{
77-
test: /\.(png|jpe?g|gif|svg|eot|woff|ttf|woff2)$/,
78-
type: 'asset',
79-
generator: {
80-
filename: '[name]-[contenthash][ext]',
81-
},
82-
parser: {
83-
dataUrlCondition: {
84-
maxSize: 10000,
85-
},
86-
},
87-
},
88-
],
93+
rules,
8994
},
9095
node: {
9196
__filename: true,

packages/kolibri-tools/lib/webpack.config.plugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ const WebpackMessages = require('./webpackMessages');
3636
*/
3737
module.exports = (
3838
data,
39-
{ mode = 'development', hot = false, port = 3000, address = 'localhost', cache = false } = {}
39+
{
40+
mode = 'development',
41+
hot = false,
42+
port = 3000,
43+
address = 'localhost',
44+
cache = false,
45+
transpile = false,
46+
} = {}
4047
) => {
4148
if (
4249
typeof data.name === 'undefined' ||
@@ -164,7 +171,7 @@ module.exports = (
164171
);
165172
}
166173

167-
bundle = merge(bundle, baseConfig({ mode, hot, cache }), webpackConfig);
174+
bundle = merge(bundle, baseConfig({ mode, hot, cache, transpile }), webpackConfig);
168175

169176
if (mode === 'development') {
170177
const publicPath = `http://${address}:${port}/${data.name}/`;

0 commit comments

Comments
 (0)