Skip to content

fix(build): Exclude test files #105

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

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var conf = require('./config');
var webpack = require('webpack');
var merge = require('webpack-merge');

const testFilePattern = "\\.(test|spec)\\.?";

// custom babel target for each node version
function getBabelTarget(envConfig) {
var key = 'AWS_LAMBDA_JS_RUNTIME';
Expand Down Expand Up @@ -75,7 +77,9 @@ function webpackConfig(dir, additionalConfig) {
rules: [
{
test: /\.(m?js|ts)?$/,
exclude: /(node_modules|bower_components)/,
exclude: new RegExp(
`(node_modules|bower_components|${testFilePattern})`
),
use: {
loader: 'babel-loader',
options: babelOpts
Expand All @@ -99,8 +103,10 @@ function webpackConfig(dir, additionalConfig) {
};
fs.readdirSync(dirPath).forEach(function(file) {
if (file.match(/\.(m?js|ts)$/)) {
var name = file.replace(/\.(m?js|ts)$/, '');
webpackConfig.entry[name] = './' + file;
var name = file.replace(/\.(m?js|ts)$/, "");
if (!name.match(new RegExp(testFilePattern))) {
webpackConfig.entry[name] = "./" + file;
}
}
});
if (Object.keys(webpackConfig.entry) < 1) {
Expand Down