diff --git a/packages/react-server-cli/bin/react-server-cli b/packages/react-server-cli/bin/react-server-cli index 26166c270..c3e7acdbb 100755 --- a/packages/react-server-cli/bin/react-server-cli +++ b/packages/react-server-cli/bin/react-server-cli @@ -1,8 +1,5 @@ #!/usr/bin/env node require("babel-core/register"); -require.extensions['.css'] = function(module, filename) { - return module._compile("", filename); -}; require("../target/cli.js"); diff --git a/packages/react-server-cli/package.json b/packages/react-server-cli/package.json index a8e332175..638b77f88 100644 --- a/packages/react-server-cli/package.json +++ b/packages/react-server-cli/package.json @@ -22,6 +22,7 @@ "css-loader": "~0.15.4", "express": "~4.13.1", "extract-text-webpack-plugin": "~0.8.2", + "file-loader": "~0.8.5", "mkdirp": "~0.5.1", "node-libs-browser": "~0.5.2", "null-loader": "~0.1.1", diff --git a/packages/react-server-cli/src/compileClient.js b/packages/react-server-cli/src/compileClient.js index 474136c5f..459430905 100644 --- a/packages/react-server-cli/src/compileClient.js +++ b/packages/react-server-cli/src/compileClient.js @@ -135,10 +135,15 @@ const packageCodeForBrowser = (entrypoints, outputDir, outputUrl, hot, minify, l exclude: /node_modules/, }, { - test: /.css$/, + test: /\.css$/, loader: extractTextLoader, exclude: /node_modules/, }, + { + test: /\.(eot|woff|woff2|ttf|ttc|png|svg|jpg|jpeg|gif|cgm|tiff|webp|bmp|ico)$/i, + loader: "file", + exclude: /node_modules/, + }, ], }, resolve: { diff --git a/packages/react-server-cli/src/index.js b/packages/react-server-cli/src/index.js index f03a75658..4ea09f867 100644 --- a/packages/react-server-cli/src/index.js +++ b/packages/react-server-cli/src/index.js @@ -1,3 +1,7 @@ -import startServer from "./startServer" +require.extensions['.css'] = function(module, filename) { + return module._compile("", filename); +}; -export {startServer as start} +module.exports = { + start: require("./startServer").default, +}; diff --git a/packages/react-server-integration-tests/gulpfile.babel.js b/packages/react-server-integration-tests/gulpfile.babel.js index 4df5b78b8..a497dd0ad 100644 --- a/packages/react-server-integration-tests/gulpfile.babel.js +++ b/packages/react-server-integration-tests/gulpfile.babel.js @@ -1,4 +1,5 @@ import babel from "gulp-babel" +import filter from "gulp-filter" import gulp from "gulp" import jasmine from "gulp-jasmine" import minimist from "minimist" @@ -33,8 +34,12 @@ function getSpecGlob (prefix) { return specs; } gulp.task("compile", () => { - return gulp.src("src/**/*.js") - .pipe(babel()) + const jsFilter = filter("**/*.js"); + + return gulp.src("src/**") + .pipe(jsFilter) + .pipe(babel()) + .pipe(jsFilter.restore()) .pipe(gulp.dest("target")); }); diff --git a/packages/react-server-integration-tests/src/__tests__/css/BasicCss.css b/packages/react-server-integration-tests/src/__tests__/css/BasicCss.css new file mode 100644 index 000000000..e886a28b6 --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/BasicCss.css @@ -0,0 +1,3 @@ +.red { + color: "#FF0000"; +} diff --git a/packages/react-server-integration-tests/src/__tests__/css/CssPage.js b/packages/react-server-integration-tests/src/__tests__/css/CssPage.js new file mode 100644 index 000000000..76aa3a633 --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/CssPage.js @@ -0,0 +1,9 @@ +var React = require("react"); +var BasicCss = require("./BasicCss.css"); + +class CssPage { + getElements() { + return
Hello, world!
; + } +} +module.exports = CssPage; diff --git a/packages/react-server-integration-tests/src/__tests__/css/CssSpec.js b/packages/react-server-integration-tests/src/__tests__/css/CssSpec.js new file mode 100644 index 000000000..502a494ad --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/CssSpec.js @@ -0,0 +1,35 @@ +var helper = require("../../specRuntime/testHelper"); + +describe("A CSS page", () => { + + helper.startServerBeforeAll(__filename, [ + "./CssPage", + ]); + + helper.stopServerAfterAll(); + + describe("can apply a css class", () => { + helper.testWithDocument("/css", (document) => { + expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/route0\.css/); + }); + }); + +}); + +describe("A CSS page with assets", () => { + + helper.startServerBeforeAll(__filename, [ + "./CssWithAssetsPage", + ]); + + helper.stopServerAfterAll(); + + describe("can apply a css class", () => { + helper.testWithDocument("/cssWithAssets", (document) => { + // this test is really just to make sure that react-server-cli doesn't explode + // when compiling CSS that includes images and fonts. + expect(document.querySelector("head link[rel=stylesheet]").href).toMatch(/route0\.css/); + }); + }); + +}); diff --git a/packages/react-server-integration-tests/src/__tests__/css/CssWithAssets.css b/packages/react-server-integration-tests/src/__tests__/css/CssWithAssets.css new file mode 100644 index 000000000..06c32fea2 --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/CssWithAssets.css @@ -0,0 +1,34 @@ +.foo { + background-image: url("./images/cat.png"); +} +.bar { + background-image: url("http://example.com/doesNotExist.png"); +} +@font-face { + font-family: myFontWoff; + src: url(./fonts/Prociono-Regular-webfont.woff); +} +@font-face { + font-family: myFontTtf; + src: url(./fonts/Prociono-Regular-webfont.ttf); +} +@font-face { + font-family: myFontEot; + src: url(./fonts/Prociono-Regular-webfont.eot); +} +@font-face { + font-family: myFontSvg; + src: url(./fonts/Prociono-Regular-webfont.svg); +} +.woff { + font-family: myFontWoff; +} +.ttf { + font-family: myFontTtf; +} +.eot { + font-family: myFontEot; +} +.svg { + font-family: myFontSvg; +} diff --git a/packages/react-server-integration-tests/src/__tests__/css/CssWithAssetsPage.js b/packages/react-server-integration-tests/src/__tests__/css/CssWithAssetsPage.js new file mode 100644 index 000000000..8edf48df4 --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/CssWithAssetsPage.js @@ -0,0 +1,9 @@ +var React = require("react"); +var css = require("./CssWithAssets.css"); + +class CssWithAssetsPage { + getElements() { + return
Hello, world!
; + } +} +module.exports = CssWithAssetsPage; diff --git a/packages/react-server-integration-tests/src/__tests__/css/fonts/Open Font License.markdown b/packages/react-server-integration-tests/src/__tests__/css/fonts/Open Font License.markdown new file mode 100644 index 000000000..03f98b700 --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/fonts/Open Font License.markdown @@ -0,0 +1,105 @@ + Copyright (c) 2009, Barry Schwartz , with Reserved Font Name OFL "Prociono". + + This Font Software is licensed under the SIL Open Font License, Version 1.1. + This license is copied below, and is also available with a FAQ at: + http://scripts.sil.org/OFL + + Version 1.1 - 26 February 2007 + + +SIL Open Font License +==================================================== + + +Preamble +---------- + +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +Definitions +------------- + +`"Font Software"` refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +`"Reserved Font Name"` refers to any names specified as such after the +copyright statement(s). + +`"Original Version"` refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +`"Modified Version"` refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +`"Author"` refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +Permission & Conditions +------------------------ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1. Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2. Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3. No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5. The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +Termination +----------- + +This license becomes null and void if any of the above conditions are +not met. + + + DISCLAIMER + + THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE + COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM + OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.eot b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.eot new file mode 100644 index 000000000..9f427769d Binary files /dev/null and b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.eot differ diff --git a/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.svg b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.svg new file mode 100644 index 000000000..c8f67ae0c --- /dev/null +++ b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.svg @@ -0,0 +1,150 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : This font has been released into the public domain by its author Barry Schwartz This applies worldwideIn some countries this may not be legally possible if soBarry Schwartz grants anyone the right to use this work for any purpose without any conditions unless such conditions are required by law +Designer : Barry Schwartz +Foundry : The Crud Factory La Rubejplenigejo +Foundry URL : httpcrudfactorycom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.ttf b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.ttf new file mode 100644 index 000000000..235e5edee Binary files /dev/null and b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.ttf differ diff --git a/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.woff b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.woff new file mode 100644 index 000000000..a739e92fc Binary files /dev/null and b/packages/react-server-integration-tests/src/__tests__/css/fonts/Prociono-Regular-webfont.woff differ diff --git a/packages/react-server-integration-tests/src/__tests__/css/images/cat.png b/packages/react-server-integration-tests/src/__tests__/css/images/cat.png new file mode 100644 index 000000000..133fb1ed2 Binary files /dev/null and b/packages/react-server-integration-tests/src/__tests__/css/images/cat.png differ