diff --git a/packages/falcon-client/package.json b/packages/falcon-client/package.json index ce0edc6ce..551594368 100644 --- a/packages/falcon-client/package.json +++ b/packages/falcon-client/package.json @@ -1,6 +1,6 @@ { "name": "@deity/falcon-client", - "version": "0.0.2", + "version": "0.0.4", "license": "OSL-3.0", "main": "index.js", "repository": "https://github.com/deity-io/falcon/tree/master/packages/falcon-client", @@ -88,6 +88,7 @@ "react-i18next": "^7.11.0", "react-test-renderer": "^16.4.2", "supertest": "^3.3.0", + "webpack-node-externals": "^1.7.2", "workbox-build": "^3.5.0" }, "devDependencies": {}, diff --git a/packages/falcon-client/src/buildTools/razzle/falconClientPlugin.js b/packages/falcon-client/src/buildTools/razzle/falconClientPlugin.js index b289688b5..ab78932a2 100644 --- a/packages/falcon-client/src/buildTools/razzle/falconClientPlugin.js +++ b/packages/falcon-client/src/buildTools/razzle/falconClientPlugin.js @@ -5,6 +5,7 @@ const FalconI18nLocalesPlugin = require('@deity/falcon-i18n-webpack-plugin'); const razzlePluginTypescript = require('razzle-plugin-typescript'); const WebpackConfigHelpers = require('razzle-dev-utils/WebpackConfigHelpers'); const AssetsPlugin = require('assets-webpack-plugin'); +const NodeExternals = require('webpack-node-externals'); const paths = require('./../paths'); const webpackConfigHelper = new WebpackConfigHelpers(paths.razzle.appPath); @@ -124,7 +125,6 @@ function addGraphQLTagLoader(config) { config.module.rules.push({ test: /\.(graphql|gql)$/, - exclude: /node_modules/, include: [paths.falconClient.appSrc], use: require.resolve('graphql-tag/loader') }); @@ -200,6 +200,25 @@ function addWebManifest(config, target) { } } +function addToNodeExternals(whitelist) { + return (config, { target, dev }) => { + if (target === 'node') { + config.externals = [ + NodeExternals({ + whitelist: [ + dev ? 'webpack/hot/poll?300' : null, + /\.(eot|woff|woff2|ttf|otf)$/, + /\.(svg|png|jpg|jpeg|gif|ico)$/, + /\.(mp4|mp3|ogg|swf|webp)$/, + /\.(css|scss|sass|sss|less)$/, + ...whitelist + ].filter(x => x) + }) + ]; + } + }; +} + /** * falcon-client and razzle integration plugin * @param {{i18n: i18nPluginConfig }} appConfig webpack config @@ -213,9 +232,10 @@ module.exports = appConfig => (config, { target, dev }, webpackObject) => { }; setEntryToFalconClient(config, target); - extendBabelInclude([paths.falconClient.appSrc, path.join(paths.resolvePackageDir('@deity/falcon-ui'), 'src')])( - config - ); + // make sure that webpack handle @deity/falcon-client from shop directory + extendBabelInclude([paths.falconClient.appSrc, /\/@deity\/falcon-client\//])(config); + addToNodeExternals([/\/@deity\/falcon-client\//])(config, { target, dev }); + addTypeScript(config, { target, dev }, webpackObject); fixUrlLoaderFallback(config, target); fixAssetsWebpackPlugin(config, target);