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

Commit 7fa759c

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

File tree

12 files changed

+46
-29
lines changed

12 files changed

+46
-29
lines changed

index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 5 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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+
}
File renamed without changes.

test/__snapshots__/loader.test.js.snap

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
],

0 commit comments

Comments
 (0)