webpack-node-externals is not excluding node_modules


(sebastian nielsen) #1

webpack-cli version = 3.1.0

package.json

   {
  "name": "zinuku",
  "version": "1.0.0",
  "description": "",
  "main": "index.jsx",
  "scripts": {
    "build": "webpack-cli",
    "start": "webpack-dev-server"
  },
  "dependencies": {
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.16.3",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5",
    "webpack-node-externals": "^1.7.2"
  }
}

webpack.config.js

const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');

var HTMLWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
    template: __dirname + '/app/index.html',
    filename: 'index.html',
    inject: 'body'
});


module.exports = {
    entry: __dirname + '/app/index.jsx',
    mode: 'development',
    target: 'node', // in order too ignore built-in modules like path, fs, etc.
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.jsx$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            }
        ]
    },
    output: {
        filename: 'transformed.js',
        path:  __dirname + '/build'
    },
    plugins: [HTMLWebpackPluginConfig]
};

Bash (displaying that node_modules got build too!)

npm run start

> zinuku@1.0.0 start C:\Users\sebas\pycharmProjects\zinuku
> webpack-dev-server

i 「wds」: Project is running at http://localhost:8081/
i 「wds」: webpack output is served from /
i 「wdm」: Hash: 94790fc256e631986c59
Version: webpack 4.16.3
Time: 873ms
Built at: 2018-07-31 20:44:54
         Asset       Size  Chunks             Chunk Names
transformed.js     27 KiB    main  [emitted]  main
    index.html  221 bytes          [emitted]
Entrypoint main = transformed.js
[./app/components/App.jsx] 386 bytes {main} [built]
[./app/components/HeaderComponent/NavBar.jsx] 294 bytes {main} [built]
[./app/index.jsx] 209 bytes {main} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:8081] (webpack)-dev-server/client?http://localhost:8081 7.78 KiB {main} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
[./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
[loglevel] external "loglevel" 42 bytes {main} [built]
[react] external "react" 42 bytes {main} [built]
[react-dom] external "react-dom" 42 bytes {main} [built]
[sockjs-client/dist/sockjs] external "sockjs-client/dist/sockjs" 42 bytes {main} [built]
[strip-ansi] external "strip-ansi" 42 bytes {main} [built]
[url] external "url" 42 bytes {main} [built]
[webpack/hot/emitter] external "webpack/hot/emitter" 42 bytes {main} [built]
[0] multi (webpack)-dev-server/client?http://localhost:8081 ./app/index.jsx 40 bytes {main} [built]
    + 3 hidden modules
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [./node_modules/html-webpack-plugin/lib/loader.js!./app/index.html] 372 bytes {0} [built]
    [./node_modules/lodash/lodash.js] 527 KiB {0} [built]
    [./node_modules/webpack/buildin/module.js] 497 bytes {0} [built]
i 「wdm」: Compiled successfully.

My file structure: https://gyazo.com/670cf8afbae2fb213d759d455221d7f3


(Kat Marchán) #2

@sebastian3495 this is not an npm issue. npm.community is for the npm CLI, its registry, and such products and tools, not for support with individual libraries hosted on the registry.

Please forward this to the webpack-node-externals issue tracker.


(sebastian nielsen) #3

I forgot to add, that even without the use of webpack-node-externals, I still somehow is unable to exclude node_modules. I assume this also regards npm now?


(Kat Marchán) #4

npm doesn’t define webpack’s own behavior. If it’s a webpack bug, you have to then go to webpack’s issue tracker, and so on.


(sebastian nielsen) #5

Will do then. You may delete this thread.


(Kat Marchán) #6