Skip to content

Commit

Permalink
Only build necessary files for test envs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Dec 3, 2018
1 parent 197c76e commit 49c7265
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 54 deletions.
15 changes: 5 additions & 10 deletions .travis.yml
@@ -1,18 +1,13 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
node_js:
- '10'
node_js: node
cache: npm
env:
- TEST_ENV=cjs
- TEST_ENV=umd
- TEST_ENV=cjs BUILD_ENV=cjs
- TEST_ENV=umd BUILD_ENV=umd
- TEST_ENV=source
install:
- npm ci
before_script:
- npm run build
- ([[ -z "$BUILD_ENV" ]] || npm run build)
script:
- npm run lint
- npm test
13 changes: 3 additions & 10 deletions karma.conf.js
Expand Up @@ -2,7 +2,7 @@ var path = require('path');
var webpack = require('webpack');
var projectName = require('./package').name;

module.exports = config => {
module.exports = function(config) {
var customLaunchers = {
BS_Chrome: {
base: 'BrowserStack',
Expand Down Expand Up @@ -55,7 +55,7 @@ module.exports = config => {
}
};

let historyAlias;
var historyAlias;
switch (process.env.TEST_ENV) {
case 'cjs':
historyAlias = 'cjs/history.js';
Expand All @@ -69,17 +69,13 @@ module.exports = config => {

config.set({
customLaunchers: customLaunchers,

browsers: ['Chrome'],
frameworks: ['mocha'],
reporters: ['mocha'],

files: ['tests.webpack.js'],

preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap']
},

webpack: {
devtool: 'inline-source-map',
module: {
Expand All @@ -102,7 +98,6 @@ module.exports = config => {
})
]
},

webpackServer: {
noInfo: true
}
Expand All @@ -112,18 +107,16 @@ module.exports = config => {
config.browsers = Object.keys(customLaunchers);
config.reporters = ['dots'];
config.concurrency = 2;

config.browserDisconnectTimeout = 10000;
config.browserDisconnectTolerance = 3;

if (process.env.TRAVIS) {
config.singleRun = true;
config.browserStack = {
project: projectName,
build: process.env.TRAVIS_BUILD_NUMBER,
name: process.env.TRAVIS_JOB_NUMBER
};

config.singleRun = true;
} else {
config.browserStack = {
project: projectName
Expand Down
9 changes: 2 additions & 7 deletions modules/.eslintrc
@@ -1,15 +1,10 @@
{
"parser": "babel-eslint",
"plugins": [
"import"
],
"plugins": ["import"],
"env": {
"browser": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors"
],
"extends": ["eslint:recommended", "plugin:import/errors"],
"rules": {
"prefer-arrow-callback": 2
}
Expand Down
79 changes: 52 additions & 27 deletions rollup.config.js
Expand Up @@ -8,72 +8,97 @@ import { uglify } from 'rollup-plugin-uglify';
import pkg from './package.json';

const input = './modules/index.js';
const name = 'History';
const babelOptionsCJS = {
exclude: /node_modules/
};
const babelOptionsESM = {
exclude: /node_modules/,
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules: true }]]
};
const commonjsOptions = {
include: /node_modules/
};
const globalName = 'History';

const external = id => !id.startsWith('.') && !id.startsWith('/');
function external(id) {
return !id.startsWith('.') && !id.startsWith('/');
}

export default [
const cjs = [
{
input,
output: { file: `cjs/${pkg.name}.js`, format: 'cjs' },
external,
plugins: [
babel(babelOptionsCJS),
babel({ exclude: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') })
]
},

{
input,
output: { file: `cjs/${pkg.name}.min.js`, format: 'cjs' },
external,
plugins: [
babel(babelOptionsCJS),
babel({ exclude: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
uglify()
]
},
}
];

const esm = [
{
input,
output: { file: `esm/${pkg.name}.js`, format: 'esm' },
external,
plugins: [babel(babelOptionsESM), sizeSnapshot()]
},
plugins: [
babel({
exclude: /node_modules/,
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules: true }]]
}),
sizeSnapshot()
]
}
];

const umd = [
{
input,
output: { file: `umd/${pkg.name}.js`, format: 'umd', name },
output: { file: `umd/${pkg.name}.js`, format: 'umd', name: globalName },
plugins: [
babel(babelOptionsESM),
babel({
exclude: /node_modules/,
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules: true }]]
}),
nodeResolve(),
commonjs(commonjsOptions),
commonjs({ include: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
sizeSnapshot()
]
},

{
input,
output: { file: `umd/${pkg.name}.min.js`, format: 'umd', name },
output: { file: `umd/${pkg.name}.min.js`, format: 'umd', name: globalName },
plugins: [
babel(babelOptionsESM),
babel({
exclude: /node_modules/,
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules: true }]]
}),
nodeResolve(),
commonjs(commonjsOptions),
commonjs({ include: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
sizeSnapshot(),
uglify()
]
}
];

let config;
switch (process.env.BUILD_ENV) {
case 'cjs':
config = cjs;
break;
case 'esm':
config = esm;
break;
case 'umd':
config = umd;
break;
default:
config = cjs.concat(esm).concat(umd);
}

export default config;

0 comments on commit 49c7265

Please sign in to comment.