Skip to content

Commit ec0a39e

Browse files
GeeWeeDorianGrey
authored andcommitted
Added the abillity to import js and jsx files with ts-loader (wmonk#242)
* added js and jsx to things that ts-loader loads * removed spaces and made prettier runnable on windows * run jsx specs too * added isejecting * added dependencies and babeltransform * bumped jest version# * does it work without cache? * cache? * added ts * updates ts-jest * readd caching * removed ts as a devdependency * added babel to handle js files * added prod env * prod is handled by babel loader * added ts as devdep * cache node modules * fixed legal
1 parent 7149b37 commit ec0a39e

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"publish": "tasks/release.sh",
1111
"start": "node packages/react-scripts/scripts/start.js",
1212
"test": "node packages/react-scripts/scripts/test.js --env=jsdom",
13-
"format": "prettier --trailing-comma es5 --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
13+
"format": "prettier --trailing-comma es5 --single-quote --write \"packages/*/*.js\" \"packages/*/!(node_modules)/**/*.js\"",
1414
"precommit": "lint-staged"
1515
},
1616
"devDependencies": {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @remove-file-on-eject
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
'use strict';
9+
10+
const babelJest = require('babel-jest');
11+
12+
module.exports = babelJest.createTransformer({
13+
presets: [require.resolve('babel-preset-react-app')],
14+
babelrc: false,
15+
});

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = {
124124
// please link the files into your node_modules/ and let module-resolution kick in.
125125
// Make sure your source files are compiled, as they will not be processed in any way.
126126
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
127-
new TsconfigPathsPlugin({configFile: paths.appTsConfig})
127+
new TsconfigPathsPlugin({ configFile: paths.appTsConfig }),
128128
],
129129
},
130130
module: {
@@ -156,6 +156,19 @@ module.exports = {
156156
name: 'static/media/[name].[hash:8].[ext]',
157157
},
158158
},
159+
{
160+
test: /\.(js|jsx|mjs)$/,
161+
include: paths.appSrc,
162+
loader: require.resolve('babel-loader'),
163+
options: {
164+
// @remove-on-eject-begin
165+
babelrc: false,
166+
presets: [require.resolve('babel-preset-react-app')],
167+
// @remove-on-eject-end
168+
compact: true,
169+
},
170+
},
171+
159172
// Compile .tsx?
160173
{
161174
test: /\.(ts|tsx)$/,

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module.exports = {
130130
// please link the files into your node_modules/ and let module-resolution kick in.
131131
// Make sure your source files are compiled, as they will not be processed in any way.
132132
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
133-
new TsconfigPathsPlugin({configFile: paths.appTsConfig})
133+
new TsconfigPathsPlugin({ configFile: paths.appTsConfig }),
134134
],
135135
},
136136
module: {
@@ -160,6 +160,18 @@ module.exports = {
160160
name: 'static/media/[name].[hash:8].[ext]',
161161
},
162162
},
163+
{
164+
test: /\.(js|jsx|mjs)$/,
165+
include: paths.appSrc,
166+
loader: require.resolve('babel-loader'),
167+
options: {
168+
// @remove-on-eject-begin
169+
babelrc: false,
170+
presets: [require.resolve('babel-preset-react-app')],
171+
// @remove-on-eject-end
172+
compact: true,
173+
},
174+
},
163175
// Compile .tsx?
164176
{
165177
test: /\.(ts|tsx)$/,

packages/react-scripts/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
},
2323
"dependencies": {
2424
"autoprefixer": "7.1.6",
25+
"babel-jest": "^22.1.0",
26+
"babel-loader": "^7.1.2",
27+
"babel-preset-react-app": "^3.1.1",
2528
"case-sensitive-paths-webpack-plugin": "2.1.1",
2629
"chalk": "1.1.3",
2730
"css-loader": "0.28.7",
@@ -31,7 +34,7 @@
3134
"fork-ts-checker-webpack-plugin": "^0.2.8",
3235
"fs-extra": "3.0.1",
3336
"html-webpack-plugin": "2.29.0",
34-
"jest": "20.0.4",
37+
"jest": "22.1.4",
3538
"object-assign": "4.1.1",
3639
"postcss-flexbugs-fixes": "3.2.0",
3740
"postcss-loader": "2.0.8",
@@ -41,7 +44,7 @@
4144
"source-map-loader": "^0.2.1",
4245
"style-loader": "0.19.0",
4346
"sw-precache-webpack-plugin": "0.11.4",
44-
"ts-jest": "^20.0.7",
47+
"ts-jest": "22.0.1",
4548
"ts-loader": "^2.3.7",
4649
"tsconfig-paths-webpack-plugin": "^2.0.0",
4750
"tslint": "^5.7.0",
@@ -54,7 +57,8 @@
5457
},
5558
"devDependencies": {
5659
"react": "^15.5.4",
57-
"react-dom": "^15.5.4"
60+
"react-dom": "^15.5.4",
61+
"typescript": "^2.7.1"
5862
},
5963
"peerDependencies": {
6064
"typescript": "2.x"

packages/react-scripts/scripts/utils/createJestConfig.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fs = require('fs');
1111
const chalk = require('chalk');
1212
const paths = require('../../config/paths');
1313

14-
module.exports = (resolve, rootDir) => {
14+
module.exports = (resolve, rootDir, isEjecting) => {
1515
// Use this instead of `paths.testsSetup` to avoid putting
1616
// an absolute filename into configuration after ejecting.
1717
const setupTestsFile = fs.existsSync(paths.testsSetup)
@@ -25,20 +25,23 @@ module.exports = (resolve, rootDir) => {
2525
setupFiles: [resolve('config/polyfills.js')],
2626
setupTestFrameworkScriptFile: setupTestsFile,
2727
testMatch: [
28-
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
29-
'<rootDir>/src/**/?(*.)(spec|test).ts?(x)',
28+
'<rootDir>/src/**/__tests__/**/*.(j|t)s?(x)',
29+
'<rootDir>/src/**/?(*.)(spec|test).(j|t)s?(x)',
3030
],
3131
testEnvironment: 'node',
3232
testURL: 'http://localhost',
3333
transform: {
34+
'^.+\\.(js|jsx|mjs)$': isEjecting
35+
? '<rootDir>/node_modules/babel-jest'
36+
: resolve('config/jest/babelTransform.js'),
3437
'^.+\\.tsx?$': resolve('config/jest/typescriptTransform.js'),
3538
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
3639
'^(?!.*\\.(js|jsx|mjs|css|json)$)': resolve(
3740
'config/jest/fileTransform.js'
3841
),
3942
},
4043
transformIgnorePatterns: [
41-
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$'
44+
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$',
4245
],
4346
moduleNameMapper: {
4447
'^react-native$': 'react-native-web',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy