node.js - How to use Webpack loaders in a Node app? -
is there way use webpack loaders in node app / run node app in webpack environment?
for instance i've got webpack config has style-loader. in node app following:
import style 'style.css' console.log(style.someclass)
i wanna run $ node app.js
i've got idea might work, based on webpack nodejs api. if put code want able use webpack environment (with configured module loaders) module:
appmodule.js:
import style 'style.css' console.log(style.someclass)
and require
following:
app.js:
import webpack 'webpack' import memoryfs 'memory-fs' ... webpackconfig.entry = 'appmodule.js' webpackconfig.output = 'appmodule-out.js' let compiler = webpack(webpackconfig) let mfs = new memoryfs() compiler.outputfilesystem = mfs compiler.run(function (err, stats) { require(webpackconfig.output) })
probably won't work because require looks output on physical fs... can require
memory fs? have not tried yet - idea?
Comments
Post a Comment