Comments (12)
I came up with a slightly safer way of doing the same thing. It white-lists some static file types and only symlinks those. It seems like there should be a more elegant solution, but this gets the job done without too much hassle.
Some constants.
var staticAssetPath = path.join(dirs.meteor, 'public/assets');
var staticAssetWhitelist = ['png', 'jpg', 'svg', 'eot', 'woff', 'ttf', 'woff2'];
And for the linking: put the following in the compileClient
callback right before runMeteor()
in prod.js
or return callback();
in deploy.js
.
fs.readdirSync(dirs.assets).filter(function(file) {
return staticAssetWhitelist.indexOf(file.split('.').slice(-1)[0].toLowerCase()) != -1;
}).forEach(function(staticFile) {
ln('-sf', path.join(dirs.assets, staticFile), path.join(staticAssetPath, staticFile));
});
from meteor-webpack-react.
I have exactly the same problem. Css loader in prod is resolving backgrounds to the assets/...
path, which is not visible in prod. The possible solution is to put CSS files in the meteor_core directoy, losing the hot code push ... not optimal ;(
from meteor-webpack-react.
can you paste your dev and prod webpack config?
from meteor-webpack-react.
@JBBr have you changed path
or publicPath
anywhere in your webpack config? In this project the assets should be saved to /assets/...
from meteor-webpack-react.
I can reproduce this with the latest master:
- Add file loader to webpack.config.client.js
{ test: /\.jpg$/, loader: 'file' },
- Load image in App.jsx
import image from '../images/image.jpg';
....
<img src={image} />
....
-
When using ./dev:
Everything works (In this case I don't get an empty response anymore).
resultingsrc="http://0.0.0.0:9090/assets/44bae156f12e5089150d096a2cbf83c1.jpg"
-
When using ./prod:
Image url does not exist.
resultsrc="/assets/44bae156f12e5089150d096a2cbf83c1.jpg"
(http://127.0.0.1:3000/assets/44bae156f12e5089150d096a2cbf83c1.jpg
)The file exists in
webpack/assets/
but is not shipped by the meteor server in ./prod mode.
Bad workaround: symbolic link from meteor_core/public/assets
to webpack/assets
. But then also server.bundle.js
is published to the world...
from meteor-webpack-react.
@JBBr thought I had commented, we can solve this by simply making different asset directories for server and client (or even just outputting straight into the Meteor dirs)
from meteor-webpack-react.
Errr...but Meteor very unfortunately would auto-load the client.bundle.js from the asset directory as well. Maybe we'll have to go with a package.
from meteor-webpack-react.
Actually I think I can solve with separate client and server output dirs, and making meteor_core/client
a symlink to webpack's client output directory.
Yesterday I was experimenting with webpack-dev-server
's proxy: { '*': 'http://localhost:3000' }
option, hoping I would be able to open the webpage from localhost:9090
, but unfortunately Meteor's sockjs
wasn't connecting...didn't too much surprise me...
from meteor-webpack-react.
I solved it.
1.Add folder /meteor_core/public
2.modify prod.js
require('shelljs/global');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = env.NODE_ENV = 'production';
}
var fs = require('fs');
var path = require('path');
var dirs = require('./dirs');
var webpack = require('webpack');
var addProgressPlugin = require('./addProgressPlugin');
var statsOptions = require('./statsOptions');
var serverConfig = require(path.join(dirs.webpack, 'webpack.config.server.prod'));
var clientConfig = require(path.join(dirs.webpack, 'webpack.config.client.prod'));
addProgressPlugin(serverConfig);
addProgressPlugin(clientConfig);
serverConfig.plugins.push(new webpack.BannerPlugin('var require = Npm.require;\n', {raw: true}));
var serverBundlePath = path.join(dirs.assets, 'server.bundle.js');
var clientBundlePath = path.join(dirs.assets, 'client.bundle.js');
var serverBundleLink = path.join(dirs.meteor, 'server/server.bundle.min.js');
var clientBundleLink = path.join(dirs.meteor, 'client/client.bundle.min.js');
var loadClientBundleHtml = path.join(dirs.webpack, 'loadClientBundle.html');
var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html');
var requireServerBundleJs = path.join(dirs.meteor, 'server/require.server.bundle.js');
var clientAssetsPath = dirs.assets; //add
var clientAssetsLink = path.join(dirs.meteor, 'public/assets'); //add
exec('node core-js-custom-build.js');
if (fs.existsSync(loadClientBundleLink)) rm(loadClientBundleLink);
if (fs.existsSync(requireServerBundleJs)) rm(requireServerBundleJs);
var serverCompiler = webpack(serverConfig);
var serverBundleReady = false;
var clientBundleReady = false;
serverCompiler.watch(serverConfig.watchOptions || {}, function(err, stats) {
console.log(stats.toString(statsOptions));
if (!serverBundleReady) {
serverBundleReady = true;
ln('-sf', serverBundlePath, serverBundleLink);
compileClient();
}
});
function compileClient() {
var clientCompiler = webpack(clientConfig);
clientCompiler.watch(clientConfig.watchOptions || {}, function(err, stats) {
console.log(stats.toString(statsOptions));
if (!clientBundleReady) {
clientBundleReady = true;
ln('-sf', clientBundlePath, clientBundleLink);
ln('-sf', clientAssetsPath, clientAssetsLink); // add
runMeteor();
}
});
}
function runMeteor() {
cd(dirs.meteor);
exec('meteor run --production --settings ../settings/prod.json', {async: true});
}
from meteor-webpack-react.
Warning: the above is likely insecure.
@TeemoWan That assets folder also includes your server.bundle.js
file. This approach will expose that to anyone who knows what to look for. That file will contain all your server-only code, which should likely remain secret.
from meteor-webpack-react.
@defrex That should work for an unchanging list of static assets, but if you add a new asset, you'd need to restart prod.js, right? Any downsides to running this even when clientBundleReady is set?
from meteor-webpack-react.
@bpartridge It shouldn't matter. You'll need to attach it to a file watcher or something if you don't want to restart the script.
from meteor-webpack-react.
Related Issues (20)
- Stripe integration HOT 1
- Calling configure method of useraccounts package causes error HOT 2
- WebPack Syntax Error on Windows
- Why would dev.js build server only?? HOT 2
- CoffeeScript/ Usage with meteord HOT 2
- How to: Server side debugging? HOT 2
- npm WARN deprecated [email protected]: lodash@<2.0.0 is no longer maintained. Upgrade to lodash@^3.0.0 npm WARN deprecated [email protected]: lodash@<2.0.0 is no longer maintained. Upgrade to lodash@^3.0.0 HOT 3
- TypeError: Cannot read property 'loginButtons' of undefined HOT 4
- Screen stays at "Loading" HOT 2
- mailgun-js HOT 2
- Meteor 1.3 HOT 18
- Adding loaders to webpack.config.client.js HOT 2
- Code splitting doesn't work in production (because only main chunk gets copied to meteor folder) HOT 12
- Cannot import meteor modules HOT 1
- Problem using Elasticsearch HOT 4
- Weird debug issues -- out of the box HOT 1
- [ERROR] Cannot find Cannot find module 'temp' , core-js-no-number when running dev HOT 2
- GET http://localhost:9090/ 502 Bad Gateway HOT 6
- Trying to bundle a pure node.js application HOT 2
- Webpack issue loading static files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-webpack-react.