Skip to content

Webpack v5 #492

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ module.exports = {
};
```

The additional webpack config will be merged into the default config via [webpack-merge's](https://www.npmjs.com/package/webpack-merge) `merge.smart` method.
The additional webpack config will be merged into the default config via [webpack-merge's](https://www.npmjs.com/package/webpack-merge) `merge` method.

### Babel configuration

Expand Down
7 changes: 3 additions & 4 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require('fs');
var path = require('path');
var conf = require('./config');
var webpack = require('webpack');
var merge = require('webpack-merge');
const { merge } = require('webpack-merge');
const findUp = require('find-up');

const readdir = util.promisify(fs.readdir);
Expand Down Expand Up @@ -158,12 +158,11 @@ async function webpackConfig(
entry: {},
target: 'node',
plugins: [
new webpack.IgnorePlugin(/vertx/),
new webpack.IgnorePlugin({ resourceRegExp: /vertx/ }),
new webpack.DefinePlugin(defineEnv),
],
output: {
path: functionsPath,
filename: '[name].js',
libraryTarget: 'commonjs',
},
optimization: {
Expand Down Expand Up @@ -198,7 +197,7 @@ async function webpackConfig(
if (userWebpackConfig) {
var webpackAdditional = require(path.join(cwd, userWebpackConfig));

return merge.smart(webpackConfig, webpackAdditional);
return merge(webpackConfig, webpackAdditional);
}

return webpackConfig;
Expand Down
68 changes: 49 additions & 19 deletions lib/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,58 @@ describe('build', () => {
).rejects.toThrow('Cannot find module');
});

it('should merge webpack custom config', async () => {
const script = `module.exports = () => console.log("hello world")`;
await writeFileInFunctions(script, 'index.js');
describe('webpack custom config merge', () => {
it('should merge plugins', async () => {
const script = `module.exports = () => console.log("hello world")`;
await writeFileInFunctions(script, 'index.js');

const webpackConfig = `
const webpack = require('webpack');
module.exports = { plugins: [new webpack.EnvironmentPlugin(['NODE_ENV'])] };
`;

const suffix = expect.getState().currentTestName.replace(/\s+/g, '_');
const userWebpackConfig = await writeFileInBuild(
webpackConfig,
`webpack/webpack_${suffix}.js`,
);

const stats = await build.run(functions, {
userWebpackConfig,
});
expect(stats.compilation.errors).toHaveLength(0);
expect(stats.compilation.options.plugins).toHaveLength(3);
expect(
stats.compilation.options.plugins.map(
(plugin) => plugin.constructor.name,
),
).toEqual(['IgnorePlugin', 'DefinePlugin', 'EnvironmentPlugin']);
});

const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }`;
const userWebpackConfig = await writeFileInBuild(
webpackConfig,
'webpack/webpack.js',
);
it('should merge resolve extensions', async () => {
const script = `module.exports = () => console.log("hello world")`;
await writeFileInFunctions(script, 'index.js');

const stats = await build.run(functions, {
userWebpackConfig,
const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }`;
const suffix = expect.getState().currentTestName.replace(/\s+/g, '_');
const userWebpackConfig = await writeFileInBuild(
webpackConfig,
`webpack/webpack_${suffix}.js`,
);

const stats = await build.run(functions, {
userWebpackConfig,
});
expect(stats.compilation.errors).toHaveLength(0);
expect(stats.compilation.options.resolve.extensions).toEqual([
'.wasm',
'.mjs',
'.js',
'.json',
'.ts',
'.custom',
]);
});
expect(stats.compilation.errors).toHaveLength(0);
expect(stats.compilation.options.resolve.extensions).toEqual([
'.wasm',
'.mjs',
'.js',
'.json',
'.ts',
'.custom',
]);
});

describe('babel config file resolution', () => {
Expand Down
Loading