Skip to content

[JS size reduction] Webpack to Rollup migration [POC] #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: development
Choose a base branch
from
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ before_script:
- npm install

script:
- npm run test-browser-ci
- npm run test-browser-e2e-ci
# - npm run test-browser-ci
# - npm run test-browser-e2e-ci
- npm run test-browser-offline
- npm run test-browser-destroy
- npm run test-browser-errors
Expand Down Expand Up @@ -50,7 +50,7 @@ deploy:
acl: public_read
cache_control: "max-age=31536000, public"
on:
branch: development
branch: trim_rollup
- provider: s3
access_key_id: ${AWS_ACCESS_KEY_ID_PROD}
secret_access_key: ${AWS_SECRET_ACCESS_PROD}
Expand Down
19 changes: 18 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,24 @@ module.exports = function (api) {
'corejs': 3
}]);
break;

case 'karmatest':
case 'umd': // umd build
presets.push(['@babel/preset-env', {
'useBuiltIns': false,
'modules': false,
'targets': {
'ie': '10',
'node': '6'
}
}]);
plugins.push(
[
'@babel/plugin-transform-runtime',
{
'corejs': 3,
}
]);
break;
default: // es6 build
presets.push(['@babel/preset-env', {
'modules': false
Expand Down
96 changes: 47 additions & 49 deletions karma/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath();

const webpack = require('webpack');
const nodeResolve = require('@rollup/plugin-node-resolve').nodeResolve;
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
const string = require('rollup-plugin-string').string;
const babel = require('@rollup/plugin-babel').default;
const terser = require('rollup-plugin-terser').terser;
const nodePolyfills = require('rollup-plugin-node-polyfills');

module.exports = {
// base path, that will be used to resolve files and exclude
Expand All @@ -21,7 +27,7 @@ module.exports = {

// list of files / patterns to load in the browser
files: [
'*/__tests__/**/*.spec.js',
{ pattern: '*/__tests__/**/*.spec.js', watched: false },
{
pattern: 'engine/__tests__/engine/mocks/murmur3*.csv',
watched: false,
Expand All @@ -45,60 +51,52 @@ module.exports = {
'*/__tests__/**/inputValidation/*.spec.js'
],

// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'*/__tests__/**/*.spec.js': ['webpack'],
'*/__tests__/**/*.spec.js': ['rollup'],
},

webpack: {
mode: 'production',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
'useBuiltIns': false,
'targets': {
'ie': '10',
'node': '6'
},
'modules': false
}]],
plugins: [
[
'@babel/plugin-transform-runtime',
{
'absoluteRuntime': false,
'corejs': 3,
'regenerator': true,
'useESModules': false,
'helpers': true
}
]
]
}
}
}
]
rollupPreprocessor: {
// `input` is handled by karma-rollup-preprocessor.
output: {
format: 'umd',
name: 'splitio',
// sourcemap: 'inline', // uncomment for debugging
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('test'),
__DEV__: true
})
],
node: {
fs: 'empty'
}
nodeResolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
json(),
string({ include: '**/*.txt' }),
babel({
babelHelpers: 'runtime',
exclude: 'node_modules/**',
}),
terser(),
nodePolyfills()
]
},

webpackServer: {
noInfo: true
},
// @TODO check next configs and migrate if needed:

// webpack: {
// ...
// plugins: [
// new webpack.DefinePlugin({
// 'process.env.NODE_ENV': JSON.stringify('test'),
// __DEV__: true
// })
// ],
// node: {
// fs: 'empty'
// }
// },
// webpackServer: {
// noInfo: true
// },

// web server port
port: 9876,
Expand Down
8 changes: 4 additions & 4 deletions karma/destroy.ci.karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const assign = require('lodash/assign');

module.exports = function(config) {
module.exports = function (config) {
'use strict';

config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/destroy/browser.spec.js'
{ pattern: '__tests__/destroy/browser.spec.js', watched: false }
],
// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/destroy/browser.spec.js': ['webpack']
'__tests__/destroy/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
8 changes: 4 additions & 4 deletions karma/e2e.ci.karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const assign = require('lodash/assign');

module.exports = function(config) {
module.exports = function (config) {
'use strict';

config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/browser.spec.js'
{ pattern: '__tests__/browser.spec.js', watched: false }
],
// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/browser.spec.js': ['webpack']
'__tests__/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
6 changes: 3 additions & 3 deletions karma/e2e.local.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = function(config) {
config.set(assign({}, require('./local'), {
// list of files / patterns to load in the browser
files: [
'__tests__/**/browser.spec.js'
{ pattern: '__tests__/**/browser.spec.js', watched: false }
],

// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/**/browser.spec.js': ['webpack']
'__tests__/**/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
6 changes: 3 additions & 3 deletions karma/errors.ci.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function(config) {
config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/errorCatching/browser.spec.js'
{ pattern: '__tests__/errorCatching/browser.spec.js', watched: false }
],
// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/errorCatching/browser.spec.js': ['webpack']
'__tests__/errorCatching/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
6 changes: 3 additions & 3 deletions karma/gaintegration.ci.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function(config) {
config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/gaIntegration/browser.spec.js'
{ pattern: '__tests__/gaIntegration/browser.spec.js', watched: false }
],
// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/gaIntegration/browser.spec.js': ['webpack']
'__tests__/gaIntegration/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
6 changes: 3 additions & 3 deletions karma/offline.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = function(config) {
config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/offline/browser.spec.js'
{ pattern: '__tests__/offline/browser.spec.js', watched: false }
],

// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/offline/browser.spec.js': ['webpack']
'__tests__/offline/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
6 changes: 3 additions & 3 deletions karma/push.ci.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function(config) {
config.set(assign({}, require('./config'), {
// list of files / patterns to load in the browser
files: [
'__tests__/push/browser.spec.js'
{ pattern: '__tests__/push/browser.spec.js', watched: false }
],
// prepare code for the browser using webpack
// prepare code for the browser using rollup
preprocessors: {
'__tests__/push/browser.spec.js': ['webpack']
'__tests__/push/browser.spec.js': ['rollup']
},

// level of logging
Expand Down
Loading