I'm trying to exclude some of my internal dependencies in my global script which is shared common scripts that can be later used.
Folder structure,
my-app
└────src
│ └───index.js
└────common
│ └───module.js
│
└────dist
│ └───bundle.js
│
└───gulpfile.js
index.js
import { someNodeFunction } from 'some-node-package';
import { someFunction } from '../common/module.js';
function main() {
...
...
someFunction();
...
someNodeFunction();
...
}
module.js
export function someFunction() {
...
}
gulpfile.js
var gulp = require('gulp');
const path = require('path');
var webpack = require('webpack');
var webpackGulp = require('webpack-stream');
var nodeExternals = require('webpack-node-externals');
gulp.task('bundle', function () {
gulp.src('.')
.pipe(webpackGulp({
entry: './src/index.js',
output: {
filename: 'bundle.js'
},
mode: 'production',
module: {
rules: [
{
test: /\.js$/,
exclude: [/common/]
}
]
},
externals: [nodeExternals()]
}, webpack))
.pipe(gulp.dest('./dist'));
});
package.json
{
"name": "scripts-utility",
"version": "1.0.0",
"description": "separate scripts utility",
"dependencies": {
"gulp": "^3.9.0",
"webpack": "^4.29.6",
"webpack-stream": "^5.2.1",
"webpack-node-externals": "^1.7.2"
},
"main": "index.js",
"author": "Jude Leander J",
"license": "MIT"
}
Here I could exclude the node_modules function someNodeFunction from the bundle using externals option, which seems to work fine but then when I try to exclude the someFunction from the bundle, I couldn't achieve the same. Hope, I'm missing any config...
I had also tried to provide the exclude option with 'absolute-path' with the following config,
exclude: ['common/module.js', 'common', 'common/']
But nothing seems to work.