Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 7fa759c

Browse files
authoredFeb 12, 2019
chore: integrate babel (#68)
1 parent 6519eb2 commit 7fa759c

12 files changed

+46
-29
lines changed
 

‎index.js

-20
This file was deleted.

‎package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@
77
"author": "Tobias Koppers @sokra",
88
"homepage": "https://github.com/webpack-contrib/raw-loader",
99
"bugs": "https://github.com/webpack-contrib/raw-loader/issues",
10-
"main": "index.js",
10+
"main": "dist/cjs.js",
1111
"engines": {
1212
"node": ">= 6.9.0"
1313
},
1414
"scripts": {
1515
"start": "npm run build -- -w",
16+
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
17+
"clean": "del-cli dist",
1618
"commitlint": "commitlint",
1719
"commitmsg": "commitlint -e $GIT_PARAMS",
18-
"lint": "eslint --cache index.js test",
20+
"lint": "eslint --cache src test",
21+
"prebuild": "npm run clean",
22+
"prepublish": "npm run build",
1923
"release": "standard-version",
2024
"security": "npm audit",
2125
"test": "jest",
2226
"test:watch": "jest --watch",
23-
"test:coverage": "jest --collectCoverageFrom='index.js' --coverage",
27+
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
2428
"ci:lint": "npm run lint && npm run security",
2529
"ci:test": "npm run test -- --runInBand",
2630
"ci:coverage": "npm run test:coverage -- --runInBand",
2731
"ci:lint:commits": "commitlint --from=origin/master --to=${CIRCLE_SHA1}",
2832
"defaults": "webpack-defaults"
2933
},
3034
"files": [
31-
"index.js",
32-
"options.json"
35+
"dist/"
3336
],
3437
"peerDependencies": {
3538
"webpack": "^4.3.0"

‎src/cjs.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const loader = require('./index');
2+
3+
module.exports = loader.default;

‎src/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getOptions } from 'loader-utils';
2+
import validateOptions from 'schema-utils';
3+
4+
import schema from './options.json';
5+
6+
export default function rawLoader(source) {
7+
const options = getOptions(this) || {};
8+
9+
validateOptions(schema, options, 'Raw Loader');
10+
11+
const json = JSON.stringify(source)
12+
.replace(/\u2028/g, '\\u2028')
13+
.replace(/\u2029/g, '\\u2029');
14+
15+
return `module.exports = ${json}`;
16+
}

‎options.json ‎src/options.json

File renamed without changes.

‎test/__snapshots__/loader.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ exports[`loader should works: errors 1`] = `Array []`;
44

55
exports[`loader should works: file 1`] = `"module.exports = \\"Где розы — там и тернии —\\\\nТаков закон судьбы.\\\\n\\\\nНиколай Алексеевич Некрасов\\\\n\\\\nWhere the roses are - there are thorns -\\\\nThat is the law of fate.\\\\n\\\\nNikolay Alekseevich Nekrasov\\\\n\\""`;
66

7+
exports[`loader should works: inline 1`] = `"module.exports = \\"Где розы — там и тернии —\\\\nТаков закон судьбы.\\\\n\\\\nНиколай Алексеевич Некрасов\\\\n\\\\nWhere the roses are - there are thorns -\\\\nThat is the law of fate.\\\\n\\\\nNikolay Alekseevich Nekrasov\\\\n\\""`;
8+
79
exports[`loader should works: separator 1`] = `"module.exports = \\"Word\\\\u2028Word\\\\u2029Word\\\\n\\""`;
810

911
exports[`loader should works: warnings 1`] = `Array []`;

‎test/cjs.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import src from '../src';
2+
import cjs from '../src/cjs';
3+
4+
describe('cjs', () => {
5+
it('should exported', () => {
6+
expect(cjs).toEqual(src);
7+
});
8+
});

‎test/fixtures/basic.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved
2+
import inline from '!!../../src/index.js!./file.txt';
3+
14
import txt from './file.txt';
25
import separator from './separator.txt';
36

4-
export { txt, separator };
7+
export { txt, separator, inline };

‎test/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const moduleConfig = (config) => {
1313
test: (config.loader && config.loader.test) || /\.txt/,
1414
use: [
1515
{
16-
loader: path.resolve(__dirname, '../index.js'),
16+
loader: path.resolve(__dirname, '../src/index.js'),
1717
options: (config.loader && config.loader.options) || {},
1818
},
1919
],

‎test/loader.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ describe('loader', () => {
44
it('should works', async () => {
55
const stats = await webpack('basic.js');
66
const { modules } = stats.toJson();
7-
const [, file, separator] = modules;
7+
const [inline, , file, separator] = modules;
88

9+
expect(inline.source).toMatchSnapshot('inline');
910
expect(file.source).toMatchSnapshot('file');
1011
expect(separator.source).toMatchSnapshot('separator');
12+
1113
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
1214
expect(stats.compilation.errors).toMatchSnapshot('errors');
1315
});

‎test/errors.test.js ‎test/validation.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import loader from '../index';
1+
import loader from '../src';
22

33
it('validation', () => {
44
const validate = (options) =>

0 commit comments

Comments
 (0)
This repository has been archived.