Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
[fixed] removed the unreliable webpack-combine-loaders that broke `…
Browse files Browse the repository at this point in the history
…JSCompiler#fe` in v6
  • Loading branch information
thealjey committed Feb 7, 2017
1 parent 6d21f9e commit d5f38d2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 82 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
"stylelint-scss": "^1.4.1",
"tiny-lr": "^1.0.3",
"webpack": "^1.14.0",
"webpack-combine-loaders": "^2.0.3",
"webpack-dev-server": "^1.16.3"
},
"devDependencies": {
Expand Down
64 changes: 26 additions & 38 deletions src/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import webpack from 'webpack';
import {dirname, basename} from 'path';
import combineLoaders from 'webpack-combine-loaders';
import WebpackDevServer from 'webpack-dev-server';
import MemoryFS from 'memory-fs';
import serveStatic from 'serve-static';
Expand Down Expand Up @@ -80,47 +79,41 @@ export const babelFEOptions = {
};

/**
* Returns the default set of JavaScript loaders.
* Returns a webpack configuration object.
*
* @memberof module:webpack
* @private
* @method getLoaders
* @return {Array<string | Object>} webpack JavaScript loaders
* @method getConfig
* @param {boolean} react - true if the react loader is needed
* @return {Object} webpack configuration object
*/
export function getLoaders(): Array<string | Object> {
return [{
export function getConfig(react: boolean): Object {
const loaders = [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: babelFEOptions
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /jsdom/,
loader: 'null'
}];
}

/**
* Returns a webpack configuration object.
*
* @memberof module:webpack
* @private
* @method getConfig
* @param {Array<string | Object>} loaders - the JavaScript loaders array
* @return {Object} webpack configuration object
*/
export function getConfig(loaders: Array<string | Object>): Object {
if (react) {
loaders.unshift({
test: /\.js$/,
exclude: /node_modules/,
loader: 'react-hot'
});
}

return {
cache,
debug: true,
node: {fs: 'empty'},
module: {
loaders: [{
test: /jsdom/,
loader: 'null'
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: combineLoaders(loaders)
}, {
test: /\.json$/,
loader: 'json'
}]
}
module: {loaders}
};
}

Expand All @@ -136,7 +129,7 @@ export function getConfig(loaders: Array<string | Object>): Object {
*/
export function getCompiler(inPath: string, outPath: string): Object {
const compiler = webpack({
...getConfig(getLoaders()),
...getConfig(false),
devtool: 'source-map',
entry: ['babel-polyfill', inPath],
output: {path: dirname(outPath), filename: basename(outPath), publicPath: '/'},
Expand All @@ -159,15 +152,10 @@ export function getCompiler(inPath: string, outPath: string): Object {
* @return {Object} an instance of the webpack development server
*/
export function getServer(inPath: string, options: Object) {
const {react, port, contentBase, configureApplication} = options,
loaders = getLoaders();

if (react) {
loaders.unshift('react-hot');
}
const {react, port, contentBase, configureApplication} = options;

const server = new WebpackDevServer(webpack({
...getConfig(loaders),
...getConfig(react),
devtool: 'eval-source-map',
entry: [
`webpack-dev-server/client?http://0.0.0.0:${port}`,
Expand Down
105 changes: 62 additions & 43 deletions test/webpack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,78 @@ describe('webpack', () => {
webpack = req();
});

describe('getLoaders', () => {
describe('getConfig', () => {

beforeEach(() => {
spy(webpack, 'getLoaders');
webpack.getLoaders();
spy(webpack, 'getConfig');
});

afterEach(() => {
webpack.getLoaders.restore();
webpack.getConfig.restore();
});

it('returns result', () => {
expect(webpack.getLoaders).returned([{
loader: 'babel',
query: webpack.babelFEOptions
}]);
});
describe('no react', () => {

});
beforeEach(() => {
webpack.getConfig(false);
});

describe('getConfig', () => {
it('returns result', () => {
expect(webpack.getConfig).returned({
cache: {},
debug: true,
node: {fs: 'empty'},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: webpack.babelFEOptions
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /jsdom/,
loader: 'null'
}]
}
});
});

beforeEach(() => {
spy(webpack, 'getConfig');
webpack.getConfig([
'react-hot',
{loader: 'babel', query: {something: 'here'}}
]);
});

afterEach(() => {
webpack.getConfig.restore();
});
describe('react', () => {

it('returns result', () => {
expect(webpack.getConfig).returned({
cache: {},
debug: true,
node: {fs: 'empty'},
module: {
loaders: [{
test: /jsdom/,
loader: 'null'
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'react-hot!babel?something=here'
}, {
test: /\.json$/,
loader: 'json'
}]
}
beforeEach(() => {
webpack.getConfig(true);
});

it('returns result', () => {
expect(webpack.getConfig).returned({
cache: {},
debug: true,
node: {fs: 'empty'},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'react-hot'
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: webpack.babelFEOptions
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /jsdom/,
loader: 'null'
}]
}
});
});

});

});
Expand All @@ -103,7 +122,7 @@ describe('webpack', () => {

it('calls webpack', () => {
expect(webpackFn).calledWith({
...webpack.getConfig(webpack.getLoaders()),
...webpack.getConfig(false),
devtool: 'source-map',
entry: ['babel-polyfill', 'in'],
output: {path: 'out', filename: 'file', publicPath: '/'},
Expand Down Expand Up @@ -137,7 +156,7 @@ describe('webpack', () => {

it('calls webpack', () => {
expect(webpackFn).calledWith({
...webpack.getConfig(webpack.getLoaders()),
...webpack.getConfig(false),
devtool: 'source-map',
entry: ['babel-polyfill', 'in'],
output: {path: 'out', filename: 'file', publicPath: '/'},
Expand Down Expand Up @@ -169,7 +188,7 @@ describe('webpack', () => {

it('calls webpack', () => {
expect(webpackFn).calledWith({
...webpack.getConfig(webpack.getLoaders()),
...webpack.getConfig(false),
devtool: 'eval-source-map',
entry: [
`webpack-dev-server/client?http://0.0.0.0:${WEB_PORT}`,
Expand Down Expand Up @@ -209,7 +228,7 @@ describe('webpack', () => {

it('calls webpack', () => {
expect(webpackFn).calledWith({
...webpack.getConfig(['react-hot', ...webpack.getLoaders()]),
...webpack.getConfig(true),
devtool: 'eval-source-map',
entry: [
`webpack-dev-server/client?http://0.0.0.0:${WEB_PORT}`,
Expand Down

0 comments on commit d5f38d2

Please sign in to comment.