Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webpack #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib
build
package-lock.json
yarn.lock
.vscode
2 changes: 1 addition & 1 deletion examples/web-app-react/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Schibsted",
"license": "MIT",
"scripts": {
"dev": "roc dev --runtime-applicationName 'Simple Example'"
"dev": "roc dev"
},
"dependencies": {
"roc-package-web-app-react": "^2.0.0"
Expand Down
10 changes: 10 additions & 0 deletions examples/web-app-react/simple/roc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
settings: {
runtime: {
applicationName: 'Simple Example',
},
build: {
routes: 'routes.js',
},
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"eslint-plugin-jsx-a11y": "2.2.1",
"eslint-plugin-react": "6.2.0",
"roc": "^1.0.0-rc.23",
"roc-plugin-repo": "0.0.25",
"roc-plugin-repo": "0.0.28",
"roc-plugin-repo-roc": "0.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default ({
})
);

newWebpackConfig.resolveLoader.root.push(join(__dirname, '..', '..', 'node_modules'));
newWebpackConfig.resolveLoader.modules.push(join(__dirname, '..', '..', 'node_modules'));

return newWebpackConfig;
};
4 changes: 2 additions & 2 deletions packages/roc-package-webpack-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"roc": "^1.0.0-rc.23",
"roc-abstract-package-base-dev": "^1.0.0",
"roc-plugin-babel": "^1.0.0",
"webpack": "~1.12.2",
"webpack-merge": "0.14.0"
"webpack": "~3.10.0",
"webpack-merge": "~4.1.1"
},
"roc": {
"packages": [
Expand Down
8 changes: 7 additions & 1 deletion packages/roc-package-webpack-dev/src/actions/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ export default ({ context: { verbose, config: { settings } } }) => (targets) =>

const promises = validTargets.map((target) => {
const babelConfig = invokeHook('babel-config', target);
const webpackConfig = invokeHook('build-webpack', target, babelConfig);
/* eslint-disable no-unused-vars */
const { rocMetaInfo: _, ...webpackConfig } = invokeHook(
'build-webpack',
target,
babelConfig,
);
/* eslint-enable no-unused-vars */
return build(webpackConfig, target, settings, verbose);
});

Expand Down
14 changes: 9 additions & 5 deletions packages/roc-package-webpack-dev/src/actions/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ const writeStatsFile = (buildPath, scriptPath) =>
});
});

const createWatcher = (verbose, settings, target, webpackConfig, watcher) => {
const createWatcher = (verbose, settings, target, webpackConfig, rocMetaInfo, watcher) => {
// Resolve directly if we did not get a webpackConfig back
if (!webpackConfig) {
return Promise.resolve();
}

return cleanPromise(webpackConfig.rocMetaInfo.outputPath)
return cleanPromise(rocMetaInfo.outputPath)
.then(async function watch() {
const compiler = webpack(webpackConfig);
await writeStatsFile(webpackConfig.output.path, webpackConfig.output.publicPath +
webpackConfig.output.filename.replace(/\[name\]/, webpackConfig.rocMetaInfo.outputName));
webpackConfig.output.filename.replace(/\[name\]/, rocMetaInfo.outputName));

if (!watcher[target]) {
return Promise.resolve();
Expand Down Expand Up @@ -90,7 +90,11 @@ export default ({ context: { verbose, config: { settings } } }) => (targets) =>
// Build each one in order
return Promise.all(targets.map(async function builders(target) {
const babelConfig = invokeHook('babel-config', target);
const webpackConfig = invokeHook('build-webpack', target, babelConfig);
return await createWatcher(verbose, newSettings, target, webpackConfig, watchers);
const { rocMetaInfo, ...webpackConfig } = invokeHook(
'build-webpack',
target,
babelConfig,
);
return await createWatcher(verbose, newSettings, target, webpackConfig, rocMetaInfo, watchers);
}));
};
2 changes: 1 addition & 1 deletion packages/roc-package-webpack-dev/src/roc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default {
const targets = invokeHook('get-webpack-targets');
if (targets.indexOf(target) !== -1) {
babelConfig.presets.push(
require.resolve('babel-preset-es2015'),
[require.resolve('babel-preset-es2015'), { modules: false }],
require.resolve('babel-preset-stage-1')
);
babelConfig.plugins.push(
Expand Down
39 changes: 16 additions & 23 deletions packages/roc-package-webpack-dev/src/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,44 +83,37 @@ export default () => (target, babelConfig) => (webpackConfig = {}) => {

// Base
newWebpackConfig.module = {
preLoaders: [],
loaders: [],
rules: [],
};

// JS LOADER
const jsLoader = {
id: 'babel',
test: /\.js$/,
loader: require.resolve('babel-loader'),
query: {
...babelConfig,
cacheDirectory: true,
},
include: runThroughBabel,
use: [{
loader: require.resolve('babel-loader'),
options: {
...babelConfig,
cacheDirectory: true,
},
}],
};

newWebpackConfig.module.loaders.push(jsLoader);

// JSON LOADER
const jsonLoader = {
test: /\.json$/,
loader: require.resolve('json-loader'),
};

newWebpackConfig.module.loaders.push(jsonLoader);
newWebpackConfig.module.rules.push(jsLoader);

/**
* Resolve
*/
newWebpackConfig.resolve = {
fallback: [],
extensions: ['', '.js'],
extensions: ['.js'],
modules: ['node_modules'],
alias: {},
};

newWebpackConfig.resolveLoader = {
root: [
join(__dirname, '..', '..', 'node_modules'),
],
modules: ['node_modules', join(__dirname, '..', '..', 'node_modules')],
extensions: ['.js', '.json'],
mainFields: ['loader', 'main'],
};

/**
Expand All @@ -147,7 +140,7 @@ export default () => (target, babelConfig) => (webpackConfig = {}) => {

newWebpackConfig.plugins.push(
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin()
new webpack.optimize.OccurrenceOrderPlugin()
);
}

Expand Down
Loading