My application has a directory structure, more or less like this:
src-program/- contains the code for the external interface, including package.jsonandwebpack.config.jssrc-server/- contains internal code, including various package.jsonand.babelrcshared/foo.js is JavaScript code that is required by both the external interface and the internal interface
All code uses ES2015 syntax and therefore is passed using Babel .
For the external interface, "transpilation" is performed during Webpack build using babel-loader .
For the backend, this is done on the fly babel-register .
shared/foo.jsrequires other modules that are in the files of package.jsonboth the external and internal interface.
Because NodeJS / Webpack allows modules, a common module is usually not detected.
For Webpack, I decided this is somewhat strange using this configuration:
resolve: {
root: __dirname,
fallback: [
__dirname + "/../shared",
__dirname + "/node_modules"
],
extensions: ['', '.js', '.jsx']
},
The first fallbackverifies that the "common" module is enabled, and the second fallbackensures that the modules needed for the common module are still allowed in the external interface directory node_modules.
This allows you to enable a common module so simply:
import * as foo from 'foo';
However, I am having difficulty getting the server side (i.e. NodeJS) to allow the common module in the same way.
app-module-path, foo.js, Babel, Babel, transform-runtime ( foo.js), , src-server/node_modules...
, , babe-register, .
, Webpack NodeJS?