var PIXI = require('pixi.js');
์ฒซ ๋ฒ์งธ ์๋๋ก ์ธํด ์นํฉ ์ค๋ฅ๊ฐ ๋ง์ด ๋ฐ์ํ์ต๋๋ค.
ERROR in ./~/pixi.js/src/filters/ascii/AsciiFilter.js
Module not found: Error: Cannot resolve module 'fs' in /Users/michaeldelaney/Workspace/web_dev/gulp-starter/node_modules/pixi.js/src/filters/ascii
@ ./~/pixi.js/src/filters/ascii/AsciiFilter.js 3:9-22
ERROR in ./~/pixi.js/src/filters/blur/BlurXFilter.js
Module not found: Error: Cannot resolve module 'fs' in /Users/michaeldelaney/Workspace/web_dev/gulp-starter/node_modules/pixi.js/src/filters/blur
@ ./~/pixi.js/src/filters/blur/BlurXFilter.js 3:9-22
ERROR in ./~/pixi.js/src/filters/blur/BlurYFilter.js
Module not found: Error: Cannot resolve module 'fs' in /Users/michaeldelaney/Workspace/web_dev/gulp-starter/node_modules/pixi.js/src/filters/blur
@ ./~/pixi.js/src/filters/blur/BlurYFilter.js 3:9-22
etc...
๊ทธ๋์ ๋๋ webpack์ ์ค์ ์์ node: { fs: "empty" }
๋ฅผ ์ค์ ํ๊ณ ์์ ์ค๋ฅ๋ฅผ ์ ๊ฑฐํ์ต๋๋ค.
ํ์ง๋ง์ด ์ค๋ฅ :
ERROR in ./~/pixi.js/package.json
Module parse failed: /Users/michaeldelaney/Workspace/web_dev/gulp-starter/node_modules/pixi.js/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "name": "pixi.js",
| "version": "3.0.6",
| "description": "Pixi.js is a fast lightweight 2D library that works across all devices.",
@ ./~/pixi.js/src/core/const.js 14:13-42
๊ทธ๋์ webpack์ ์ค์ ์ json-loader ๋ฅผ ์ถ๊ฐํ์ต๋๋ค.
module: {
loaders: [{
test: /\.json$/,
loader: 'json-loader'
}]
}
์ฑ๊ณต. ๊ทธ๋๋ ์ด๊ฒ์ด ์์์์ ์๋ํ๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
browserify brfs
๋ณํ์ ์ฌ์ฉํฉ๋๋ค.
https://github.com/GoodBoyDigital/pixi.js/blob/master/package.json#L57 -L61
์ด๋ป๊ฒ ๊ทธ ์นํฉ์ ํธํ ๊ฐ๋ฅํ๊ฒ ๋ง๋ค์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. browserify ๋ณํ์ ์คํํ๋ ์นํฉ์ ๋ํ ๊ธฐ์ฌ๊ฐ ์์ต๋๊น?
@drkibitz @englercj ํํธ๋ฅผ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. transform-loader + json-loader๋ฅผ ์ฌ์ฉํ์ฌ Pixi + Webpack์ ์์ํ ์์์์ต๋๋ค.
@fusepilot ์ฌ๊ธฐ์ ๋ด๊ฐ ์ฌ์ฉ์ค์ธ webpack ๊ตฌ์ฑ์ด ์์ต๋๋ค.
Babel์ ์ฌ์ฉํ ๋ @mking ๊ตฌ์ฑ์ด ์๋ํ๋๋ก ํ ์ ์์ต๋๋ค. brfs๋ฅผ postLoaders๋ก ์ฎ๊ฒจ์ผํ์ง๋ง ์ด์ ์๋ํฉ๋๋ค : https://gist.github.com/oal/898df82fa64e54dd16d0
์ด๊ฒ์ด ๋๋ต ํ ๊ฒ ๊ฐ๊ธฐ ๋๋ฌธ์ ๋ซํ๋๋ค.
pixi.js/src/core/const.js
../../package.json
๋ฅผ ์๊ตฌํ๊ณ Cannot find module "../../package.json"
์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค. @oal์ ์ํด ๋ ๊ฐ์ง ๋ฐฉ๋ฒ ์ผ๋ก ์๋ํ์ต๋๋ค. ์ด๊ฒ์ ํซ ๋ชจ๋ ์ฌ๋ก๋๋ฅผ ์ฌ์ฉํ ๋๋ง ๋ฐ์ํ์ง๋ง ํ๋ก๋์
๋น๋์์๋ ์ ๋๋ก ์๋ํฉ๋๋ค.
๋๋ import PIXI from 'pixi.js/bin/pixi.js'
์ ๊ฐ์ pixi.js์ ๋น๋ ๋ ๋ฒ์ ์ ์ฌ์ฉํ๊ฒ๋์์ต๋๋ค. ์ด์ ๊ฒฝ๊ณ ๊ฐ ํ์๋์ง๋ง ํซ ๋ฆฌ๋ก๋๊ฐ ์๋ํฉ๋๋ค.
[HMR] ./~/pixi.js/bin/pixi.js
Critical dependencies:
34:477-484 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
@ ./~/pixi.js/bin/pixi.js 34:477-484
.json์ ์ง์ํ๋ ค๋ฉด ์น ํฉ์ฉ ํ๋ฌ๊ทธ์ธ์ด ํ์ํ ์ ์์ต๋๋ค. Node / browserify๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์ํฉ๋๋ค.
@englercj json-loader
๊ตฌ์ฑ์ ์ง์๋ฉ๋๋ค. ๋๋ webpack์ ์ ๋ฌธ๊ฐ๋ ์๋์ง๋ง ๋ฒ๋ค์ด ์๋ํ๊ธฐ ๋๋ฌธ์ webpack-hot-middleware๋ก ์ธํ ๋ฌธ์ ์ผ ์ ์์ต๋๋ค. ์ค๋ฅ๋ dev ๋ชจ๋์์๋ง ๋ํ๋ฉ๋๋ค.
ํ , ์ด์ํฉ๋๋ค. ๊ทธ๋ ๋ฏธ์ ๋๋ ์ต์ํ์ง ์๋ค : /
Webpack์๋ ๊ตฌ๋ฌธ ๋ถ์ํ์ง ์๊ณ "์ฌ์ ํฌ์ฅ ๋"๋ผ์ด๋ธ๋ฌ๋ฆฌ (์ : pixi.js)๋ฅผ๋ก๋ ํ ์์๋ ์ต์ ์ด ์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ด webpack ๊ตฌ์ฑ์์ ๋ชจ๋ ์น์ ์ noParse๋ฅผ ์ถ๊ฐํ๋ฉด๋ฉ๋๋ค.
module: {
noParse: [
/.*(pixi\.js).*/
],
}
์ด ์ค ๋ํซ์ ๋ด๋ถ ์๊ตฌ ์ฌํญ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ผํฉ๋๋ค.
์ด๊ฒ์ ๋ด๊ฐ ์ฐพ์ PIXI๋ก ์นํฉ์ ๊ตฌ์ฑํ๋ ๊ฐ์ฅ ์ง์ ์ ์ด๊ณ ๊ฐ๋จํ ์์ ๋๋ค.
์ด ์์ง๋ ๊ฐ์ฅ ๊ฐ๋จํ webpack + pixi.js ๊ตฌ์ฑ์ ๋๋ค.
https://gist.github.com/mjackson/ecd3914ebee934f4daf4
(์ข์ ์๊ฒฌ๊ณผ ํจ๊ป)
์์ ๋งํฌ ๋ ์์ ์ pixijs / pixi์ ๊ด๋ จ๋ ๋ฒ๊ทธ๋ก ๊ณ ํต๋ฐ์ต๋๋ค. js @ 5a53e38 -pixi์ ๋ฒ์ ๋ฒํธ๊ฐ __VERSION__
๋ก๋ณด๊ณ ๋ฉ๋๋ค.
webpack.config.js
์๋ ๋ค์ ๋ก๋๊ฐ ํฌํจ๋์ด์ผํฉ๋๋ค.
{
include: path.resolve(__dirname, 'node_modules/pixi.js'),
loader: 'transform/cacheable?browserify-versionify'
}
์์ ๋๊ธ์ ๋ถ๋ช ํ ์๋ฆผ์ ๋ณด๋ด์ง ์๊ธฐ ๋๋ฌธ์ @mjackson์ด ์ฌ๊ธฐ์ ์ธ๊ธํ์ต๋๋ค ๐
์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์๋ฃจ์ ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!
๋ค์์ Webpack / Typescript ๋ฐ PixiJS์ ๋ํ ์์ ๊ตฌ์ฑ์ ๋๋ค. :-). https://gist.github.com/Nek-/b9775f7a88eb896db8afc37a89db3771
์ด ์ค๋ ๋๋ ๋ซํ ํ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ ๊ฒผ์ต๋๋ค. ๊ด๋ จ ๋ฒ๊ทธ์ ๋ํ ์ ๋ฌธ์ ๋ฅผ์ฌ์ญ์์ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
Webpack์๋ ๊ตฌ๋ฌธ ๋ถ์ํ์ง ์๊ณ "์ฌ์ ํฌ์ฅ ๋"๋ผ์ด๋ธ๋ฌ๋ฆฌ (์ : pixi.js)๋ฅผ๋ก๋ ํ ์์๋ ์ต์ ์ด ์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ด webpack ๊ตฌ์ฑ์์ ๋ชจ๋ ์น์ ์ noParse๋ฅผ ์ถ๊ฐํ๋ฉด๋ฉ๋๋ค.
module: { noParse: [ /.*(pixi\.js).*/ ], }
์ด ์ค ๋ํซ์ ๋ด๋ถ ์๊ตฌ ์ฌํญ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ผํฉ๋๋ค.