์ด ํจ์๋ ์๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ์ฌ socket.io-client๋ฅผ ํ์ธํฉ๋๋ค. ๊ทธ๋ฌ๋ webpack์ ์ฌ์ฉํ์ฌ webpack์ ์ฌ์ฉํ๋ nodejs ์์ฉ ํ๋ก๊ทธ๋จ์ ๋ฌถ๋ ๊ฒฝ์ฐ. ์ด๊ฒ์ node_modules์ socket.io-client์ ๋ํ ์๋ ๊ฒฝ๋ก๊ฐ ๋ฉ๋๋ค.
์คํ ์ค์ธ ๋ ธ๋๋ ๋ค์ ์ค๋ฅ๋ฅผ ๋ฐํํฉ๋๋ค.
์ค๋ฅ: "." ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค.
์ฐธ๊ณ : ๋น ๋ฅธ ๋ต๋ณ์ ์ป๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ ์๋ฅผ ๋ค์ด ๋ค์ ๋ฐ์ด์ฌ๋ฆฐ ์ ๋ถ๊ธฐํ์ฌ ์คํจํ ํ ์คํธ ์ฌ๋ก๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ๋๋ค.
๋ฒ๋ค์ ์ปดํ์ผ๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
Server.prototype.serveClient = function(v){
if (!arguments.length) return this._serveClient;
this._serveClient = v;
var resolvePath = function(file){
var filepath = path.resolve(__dirname, './../../', file);
if (exists(filepath)) {
return filepath;
}
return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
};
if (v && !clientSource) {
clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
try {
clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
} catch(err) {
debug('could not load sourcemap file');
}
}
return this;
};
ํจํค์ง๋ webpack์ผ๋ก ์ ์ปดํ์ผ๋๊ณ ์ํํ๊ฒ ์คํ๋์ด์ผ ํฉ๋๋ค.
๊ฐ์ ๋ฌธ์
socket.io์ _serving client files_ feat.
const io = require('socket.io')(httpServer, { serveClient: false })
์ด์์ ์ด์ง๋ ์์ง๋ง ์ ์ด๋ ๋ฒ๋ค์ ์๋ํฉ๋๋ค.
๋๋ ์ด๊ฒ์ด ๊ฐ์ ์ค๋ฅ๋ผ๊ณ ์๊ฐํฉ๋๋ค. webpack์ ์ฌ์ฉํ์ฌ ๋ฐํ์์ ์ป์ต๋๋ค.
Error: Cannot find module 'socket.io-client/dist/socket.io.js'
๋ด๊ฐ ์ฌ์ฉํ์ง ์๋ socket.io
์๊ธฐ๋ฅผํ์ง๋ง์ ์ข
์์ฑ์ androidjs
ํ์ ํจ์น์์ raw-loader
๋ฅผ ์ฌ์ฉํ๋ฉด ์๋ํฉ๋๋ค.
diff --git a/node_modules/socket.io/lib/index.js b/node_modules/socket.io/lib/index.js
index 5287e4e..9ee4577
--- a/node_modules/socket.io/lib/index.js
+++ b/node_modules/socket.io/lib/index.js
@@ -113,9 +113,9 @@ Server.prototype.serveClient = function(v){
return require.resolve(file);
};
if (v && !clientSource) {
- clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
+ clientSource = require( 'raw-loader!socket.io-client/dist/socket.io.js');
try {
- clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
+ clientSourceMap = require( 'raw-loader!socket.io-client/dist/socket.io.js.map');
} catch(err) {
debug('could not load sourcemap file');
}
๊ฐ์ฌํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
socket.io์ _serving client files_ feat.
const io = require('socket.io')(httpServer, { serveClient: false })
์ด์์ ์ด์ง๋ ์์ง๋ง ์ ์ด๋ ๋ฒ๋ค์ ์๋ํฉ๋๋ค.