Skip to content

Commit

Permalink
fix react example for HMR, now UI code will only trigger client refresh
Browse files Browse the repository at this point in the history
remove modules package from dependencies
fix webpack client bundle in case of working without middleware
  • Loading branch information
ardatan committed Apr 10, 2018
1 parent 5d24f57 commit 48fcf0e
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 108 deletions.
2 changes: 1 addition & 1 deletion atmosphere-packages/webpack-dev-middleware/.versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ardatan:[email protected].1
ardatan:[email protected].2
[email protected]
[email protected]
[email protected]
Expand Down
10 changes: 5 additions & 5 deletions atmosphere-packages/webpack-dev-middleware/dev-server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if (Meteor.isServer && Meteor.isDevelopment) {
const path = Npm.require('path');

const webpack = require('webpack');
let allWebpackConfigs = Npm.require('../../../../../../webpack.config.js');
const projectPath = path.resolve('.').split(path.sep + '.meteor')[0];
const webpack = Npm.require(path.join(projectPath, 'node_modules/webpack'))
const allWebpackConfigs = Npm.require(path.join(projectPath, 'webpack.config.js'), 'utf8');

if (!(allWebpackConfigs instanceof Array)) {
allWebpackConfigs = [allWebpackConfigs];
Expand All @@ -21,8 +21,8 @@ if (Meteor.isServer && Meteor.isDevelopment) {
})

if (webpackConfig && webpackConfig.devServer) {
const webpackDevMiddleware = require('webpack-dev-middleware');
const projectPath = path.resolve('.').split(path.sep + '.meteor')[0];
const webpackDevMiddleware = Npm.require(path.join(projectPath, 'node_modules/webpack-dev-middleware'))

webpackConfig.mode = 'development';
webpackConfig.externals = webpackConfig.externals || [];
Expand Down Expand Up @@ -88,7 +88,7 @@ if (Meteor.isServer && Meteor.isDevelopment) {
}, next)
});
if (webpackConfig.devServer.hot) {
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackHotMiddleware = Npm.require(path.join(projectPath, 'node_modules/webpack-hot-middleware'))
WebApp.connectHandlers.use(webpackHotMiddleware(compiler));
}
}
Expand Down
3 changes: 1 addition & 2 deletions atmosphere-packages/webpack-dev-middleware/package.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Package.describe({
name: 'ardatan:webpack-dev-middleware',
debugOnly: true,
version: '0.0.1',
version: '0.0.2',
summary: 'Webpack Dev Middleware for Meteor',
git: 'https://github.com/ardatan/meteor-webpack',
documentation: '../../README.md'
});

Package.onUse(function (api) {
api.use('[email protected]', 'server');
api.use('[email protected]', 'server');
api.addFiles('dev-server.js', 'server');
});
4 changes: 1 addition & 3 deletions atmosphere-packages/webpack/.versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
ardatan:[email protected].1_1
ardatan:[email protected].2
[email protected]
[email protected]
[email protected]
3 changes: 1 addition & 2 deletions atmosphere-packages/webpack/package.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Package.describe({
name: 'ardatan:webpack',
version: '0.0.1_1',
version: '0.0.2',
summary: 'Webpack Integration for Meteor',
git: 'https://github.com/ardatan/meteor-webpack',
documentation: '../../README.md'
});

Package.registerBuildPlugin({
name: 'webpack',
use: ['[email protected]'],
sources: ['plugin.js'],
npmDependencies: {
"jsdom": "11.6.2",
Expand Down
32 changes: 16 additions & 16 deletions atmosphere-packages/webpack/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ Plugin.registerCompiler({
const targetPlatform = targetFile.getArch().includes('web') ? 'web' : 'node';

if (typeof compilerCache[targetPlatform] === 'undefined') {
targetFile = inputFiles.find(inputFile => inputFile.getPathInPackage().endsWith('webpack.config.js'));
targetFile = inputFiles.find(inputFile => inputFile.getPathInPackage().includes('webpack.config'));
this.constructNewCompilerForTarget(targetPlatform, targetFile)
}

if (compilerCache[targetPlatform] == null) {
return;
} else {
targetFile = inputFiles.find(inputFile => inputFile.getPathInPackage().endsWith('webpack.config.js'));
targetFile = inputFiles.find(inputFile => inputFile.getPathInPackage().includes('webpack.config.js'));
}

const compiler = compilerCache[targetPlatform];
Expand Down Expand Up @@ -132,26 +132,26 @@ Plugin.registerCompiler({
for (const filePath of chunk.files) {
const absoluteFilePath = path.join(compiler.outputPath, filePath);
let data = '';
if (targetPlatform) {
if (targetPlatform == 'node') {
data = 'const require = Npm.require;'
}
data += outFs.readFileSync(absoluteFilePath, 'utf8');
if (chunk.initial && filePath.endsWith('.js')) {
targetFile.addJavaScript({
path: filePath,
hash: chunk.hash,
data,
bare: true
});
} else {
targetFile.addAsset({
path: filePath,
hash: chunk.hash,
data
});
targetFile.addJavaScript({
path: filePath,
hash: chunk.hash,
data,
bare: true
});
} else {
targetFile.addAsset({
path: filePath,
hash: chunk.hash,
data
});
}
}
}
}


}
Expand Down
3 changes: 2 additions & 1 deletion examples/react/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"env",
"react",
"stage-2"
]
],
"plugins": ["react-hot-loader/babel"]
}
1 change: 1 addition & 0 deletions examples/react/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
*.log
2 changes: 1 addition & 1 deletion examples/react/.meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected]
[email protected].1
7 changes: 4 additions & 3 deletions examples/react/client/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from 'react';
import { Meteor } from 'meteor/meteor';
import { render } from 'react-dom';

import '../imports/startup/accounts-config';
import App from '../imports/ui/App';
import App from './ui/App';

Meteor.startup(() => {
render(<App />, document.getElementById('render-target'));
});

module.hot.accept();
if(module.hot){
module.hot.accept();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';

import { Tasks } from '../api/tasks';
import { Tasks } from '../../imports/api/tasks';

import Task from './Task';
import AccountsUIWrapper from './AccountsUIWrapper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react';
import { Meteor } from 'meteor/meteor';
import classnames from 'classnames';

import { Tasks } from '../api/tasks';
import { Tasks } from '../../imports/api/tasks';

// Task component - represents a single todo item
export default class Task extends Component {
Expand Down
5 changes: 0 additions & 5 deletions examples/react/imports/startup/accounts-config.js

This file was deleted.

Loading

0 comments on commit 48fcf0e

Please sign in to comment.