Skip to content

Commit

Permalink
refactor: cjs (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 17, 2019
1 parent 609263a commit 5c51b90
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"main": "dist/index.js",
"main": "dist/cjs.js",
"engines": {
"node": ">= 8.9.0"
},
Expand Down
3 changes: 3 additions & 0 deletions src/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const loader = require('./index');

module.exports = loader.default;
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import validateOptions from 'schema-utils';

import schema from './options.json';

module.exports = () => {};
const loaderApi = () => {};

module.exports.pitch = function loader(request) {
loaderApi.pitch = function loader(request) {
const options = loaderUtils.getOptions(this) || {};

validateOptions(schema, options, {
Expand Down Expand Up @@ -192,3 +192,5 @@ ${hmrCode}`;
}
}
};

export default loaderApi;
8 changes: 8 additions & 0 deletions test/cjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import src from '../src';
import cjs from '../src/cjs';

describe('cjs', () => {
it('should exported', () => {
expect(cjs).toEqual(src);
});
});
2 changes: 1 addition & 1 deletion test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../../src'),
loader: path.resolve(__dirname, '../../src/cjs.js'),
options: loaderOptions || {},
},
loaderOptions &&
Expand Down
10 changes: 5 additions & 5 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('loader', () => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
loader: path.resolve(__dirname, '../src/cjs.js'),
options: { injectType },
},
injectType === 'linkTag'
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('loader', () => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
loader: path.resolve(__dirname, '../src/cjs.js'),
options: { injectType },
},
injectType === 'linkTag'
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('loader', () => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
loader: path.resolve(__dirname, '../src/cjs.js'),
options: { injectType },
},
injectType === 'linkTag'
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('loader', () => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
loader: path.resolve(__dirname, '../src/cjs.js'),
options: { injectType },
},
injectType === 'linkTag'
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('loader', () => {
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
loader: path.resolve(__dirname, '../src/cjs.js'),
options: { injectType },
},
injectType === 'linkTag'
Expand Down

0 comments on commit 5c51b90

Please sign in to comment.