-
-
Notifications
You must be signed in to change notification settings - Fork 866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Razzle plugins + razzle-typescript-plugin #605
Changes from 1 commit
5ac85e7
bd93f70
e97cd40
3e1df87
c7e09cb
f511a75
dc172d6
8a92ab8
4c27e1c
38b0a1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as React from 'react'; | ||
import React from 'react'; | ||
import logo from './react.svg'; | ||
|
||
import './Home.css'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import React from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix react imports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore |
||
import { hydrate } from 'react-dom'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import App from './App'; | ||
|
||
ReactDOM.hydrate( | ||
hydrate( | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as express from 'express'; | ||
import * as React from 'react'; | ||
import express from 'express'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turn on |
||
import React from 'react'; | ||
import { renderToString } from 'react-dom/server'; | ||
import { StaticRouter } from 'react-router-dom'; | ||
|
||
|
@@ -8,7 +8,7 @@ import App from './App'; | |
let assets: any; | ||
|
||
const syncLoadAssets = () => { | ||
assets = require(process.env.RAZZLE_ASSETS_MANIFEST!); | ||
assets = require(process.env.RAZZLE_ASSETS_MANIFEST!); | ||
}; | ||
syncLoadAssets(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
"no-arg": true, | ||
"no-bitwise": true, | ||
"no-consecutive-blank-lines": true, | ||
"no-console": false, | ||
"no-console": true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes developing tough. We can keep this relaxed. |
||
"no-construct": true, | ||
"no-debugger": true, | ||
"no-duplicate-variable": true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
'use strict'; | ||
|
||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); | ||
const { babelLoaderFinder, eslintLoaderFinder } = require('./helpers'); | ||
|
||
const defaultOptions = { | ||
useBabel: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use babel should be false by default |
||
tsLoader: { | ||
transpileOnly: true, | ||
experimentalWatchApi: true, | ||
}, | ||
tslintLoader: { | ||
emitErrors: true, | ||
configFile: './tslint.json', | ||
forkTsChecker: { | ||
tsconfig: './tsconfig.json', | ||
tslint: './tslint.json', | ||
watch: ['./src'], | ||
typeCheck: true, | ||
tsConfigFile: './tsconfig.json', | ||
}, | ||
}; | ||
|
||
function modify(baseConfig, configOptions, webpack, userOptions = {}) { | ||
function modify(baseConfig, { target }, webpack, userOptions = {}) { | ||
const options = Object.assign({}, defaultOptions, userOptions); | ||
const config = Object.assign({}, baseConfig); | ||
|
||
|
@@ -32,32 +34,14 @@ function modify(baseConfig, configOptions, webpack, userOptions = {}) { | |
const babelLoader = config.module.rules.find(babelLoaderFinder); | ||
if (!babelLoader) { | ||
throw new Error( | ||
`'babel-loader' was erased from config, we need it to define 'include' option` | ||
`'babel-loader' was erased from config, we need it to define 'include' option for 'ts-loader'` | ||
); | ||
} | ||
|
||
// Get the correct `include` option, since that hasn't changed. | ||
// This tells Razzle which directories to transform. | ||
const { include } = babelLoader; | ||
|
||
// Configure tslint-loader | ||
const tslintLoader = { | ||
include, | ||
enforce: 'pre', | ||
test: /\.tsx?$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('tslint-loader'), | ||
options: Object.assign( | ||
{}, | ||
defaultOptions.tslintLoader, | ||
options.tslintLoader | ||
), | ||
}, | ||
], | ||
}; | ||
config.module.rules.push(tslintLoader); | ||
|
||
// Configure ts-loader | ||
const tsLoader = { | ||
include, | ||
|
@@ -83,6 +67,16 @@ function modify(baseConfig, configOptions, webpack, userOptions = {}) { | |
|
||
config.module.rules.push(tsLoader); | ||
|
||
// Do typechecking in a separate process, | ||
// We can run it only in client builds. | ||
if (target === 'web') { | ||
config.plugins.push( | ||
new ForkTsCheckerWebpackPlugin( | ||
Object.assign({}, defaultOptions.forkTsChecker, options.forkTsChecker) | ||
) | ||
); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use
import * as React
when we haveesModuleInterop
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right sorry. I got confused for a sec