Skip to content

Commit 96cf60b

Browse files
roylee0704Danny Andrews
authored and
Danny Andrews
committed
Merge pull request roylee0704#130 from danny-andrews/build-two-versions
Build dist version (fixes roylee0704#129)
2 parents e866173 + caf25f1 commit 96cf60b

12 files changed

+97
-192
lines changed

.babelrc

-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,5 @@
33
"es2015",
44
"stage-1",
55
"react"
6-
],
7-
"plugins": [
8-
[
9-
"css-modules-transform",
10-
{
11-
"camelCase": true,
12-
"extractCss": "lib/index.css"
13-
}
14-
]
156
]
167
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
build
22
lib
3+
dist
34
node_modules
45
npm-debug.log
56
.idea

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ Otherwise you would end up with an [obscure error](https://github.com/roylee0704
7070

7171
### Isomorphic support
7272

73-
See [this comment](https://github.com/roylee0704/react-flexbox-grid/issues/28#issuecomment-198758253).
73+
Try: [this comment](https://github.com/roylee0704/react-flexbox-grid/issues/28#issuecomment-198758253).
7474

75+
If this doesn't work for you, use the build located in the dist directory. This build removes all `.css` imports and extracts the relevant css into `react-flexbox-grid/dist/react-flexbox-grid.css`.
7576

7677
### Not using a bundler?
7778

78-
If you want to use `react-flexbox-grid` the old-fashioned way, you must generate a build with all the CSS and JavaScript and include it in your `index.html`. The components will then be exposed in the `window` object.
79-
79+
Use the pre-bundled build located in the dist directory. It contains a single umd js distributable and built css file.
8080

8181
Usage
8282
-----

doc/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const express = require('express');
33
const webpack = require('webpack');
4-
const config = require('./webpack.config.development');
4+
const config = require('./webpack.config');
55

66
const app = express();
77
const compiler = webpack(config);

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const webpackConfig = require('./webpack.config.test');
1+
const webpackConfig = require('./webpack.config');
22

33
module.exports = function karmaConfig(config) {
44
config.set({

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"babel-core": "^6.24.1",
3434
"babel-eslint": "^7.2.1",
3535
"babel-loader": "^6.4.1",
36-
"babel-plugin-css-modules-transform": "^1.2.7",
3736
"babel-plugin-react-transform": "^2.0.0",
3837
"babel-polyfill": "^6.23.0",
3938
"babel-preset-env": "^1.4.0",
@@ -70,12 +69,15 @@
7069
"style-loader": "^0.12.3",
7170
"webpack": "^1.12.9",
7271
"webpack-dev-middleware": "^1.4.0",
73-
"webpack-hot-middleware": "^2.4.1"
72+
"webpack-hot-middleware": "^2.4.1",
73+
"webpack-merge": "^4.1.0"
7474
},
7575
"scripts": {
7676
"build": "cross-env NODE_ENV=production npm run compile",
7777
"clean": "rimraf ./lib",
78-
"compile": "./node_modules/.bin/babel -d ./lib ./src",
78+
"compile": "npm run compile:lib && npm run compile:dist",
79+
"compile:lib": "rm -rf lib && ./node_modules/.bin/babel -d ./lib ./src",
80+
"compile:dist": "rm -rf dist && cross-env ./node_modules/.bin/webpack",
7981
"lint": "eslint src test",
8082
"patch": "bumped release patch",
8183
"prebuild": "npm run clean",

server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const express = require('express');
33
const webpack = require('webpack');
4-
const config = require('./webpack.config.development');
4+
const config = require('./webpack.config');
55
const port = 8080;
66

77
const app = express();

webpack.config.development.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const pkg = require('./package');
22
const webpack = require('webpack');
33
const path = require('path');
4-
const autoprefixer = require('autoprefixer');
54
const ExtractTextPlugin = require('extract-text-webpack-plugin');
65

76
module.exports = {
@@ -16,23 +15,12 @@ module.exports = {
1615
publicPath: '/build/',
1716
filename: 'spec.js'
1817
},
19-
resolve: {
20-
extensions: ['', '.js', '.scss', '.json']
21-
},
2218
module: {
23-
loaders: [
24-
{
25-
test: /\.js$/,
26-
exclude: /(node_modules)/,
27-
loader: 'babel'
28-
},
29-
{
30-
test: /(\.scss|\.css)$/,
31-
loader: ExtractTextPlugin.extract('style-loader', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap')
32-
}
33-
]
19+
loaders: [{
20+
test: /(\.scss|\.css)$/,
21+
loader: ExtractTextPlugin.extract('style-loader', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap')
22+
}]
3423
},
35-
postcss: [autoprefixer],
3624
plugins: [
3725
new ExtractTextPlugin('spec.css', {allChunks: true}),
3826
new webpack.HotModuleReplacementPlugin(),

webpack.config.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const merge = require('webpack-merge');
2+
const testConfig = require('./webpack.config.test');
3+
const developmentConfig = require('./webpack.config.development');
4+
const productionConfig = require('./webpack.config.production');
5+
const autoprefixer = require('autoprefixer');
6+
7+
const configForEnv = (env) => {
8+
switch (env) {
9+
case 'test':
10+
return testConfig;
11+
case 'development':
12+
return developmentConfig;
13+
case 'production':
14+
return productionConfig;
15+
default:
16+
throw new TypeError(`Invalid environment given ${env}!`);
17+
}
18+
};
19+
20+
const baseConfig = {
21+
module: {
22+
loaders: [
23+
{
24+
test: /\.js$/,
25+
loader: 'babel',
26+
exclude: /node_modules/,
27+
}
28+
]
29+
},
30+
resolve: {
31+
extensions: ['', '.css', '.scss', '.js', '.json']
32+
},
33+
postcss: [autoprefixer]
34+
};
35+
36+
module.exports = merge(baseConfig, configForEnv(process.env.NODE_ENV));

webpack.config.production.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require('path');
2+
const pkg = require('./package.json');
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
const webpack = require('webpack');
5+
6+
const LIB_NAME = pkg.name;
7+
8+
module.exports = {
9+
entry: {
10+
[LIB_NAME]: path.resolve(__dirname, 'src')
11+
},
12+
output: {
13+
libraryTarget: 'umd',
14+
path: path.resolve(__dirname, 'dist'),
15+
library: 'ReactFlexboxGrid',
16+
filename: '[name].js',
17+
},
18+
module: {
19+
loaders: [
20+
{
21+
test: /\.css$/,
22+
loader: ExtractTextPlugin.extract('style-loader', 'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss')
23+
}
24+
],
25+
},
26+
externals: ['react'],
27+
plugins: [
28+
new webpack.DefinePlugin({
29+
'process.env.NODE_ENV': JSON.stringify('production')
30+
}),
31+
new ExtractTextPlugin('[name].css')
32+
]
33+
};

webpack.config.test.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
const webpack = require('webpack');
2-
const autoprefixer = require('autoprefixer');
32

43
module.exports = {
54
module: {
6-
loaders: [
7-
{
8-
test: /\.js$/,
9-
loader: 'babel',
10-
exclude: /(node_modules)/,
11-
}, {
12-
test: /(\.scss|\.css)$/,
13-
loader: 'style!css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass'
14-
}
15-
]
16-
},
17-
resolve: {
18-
extensions: ['', '.scss', '.js', '.json']
5+
loaders: [{
6+
test: /\.css$/,
7+
loader: 'style!css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss'
8+
}]
199
},
2010
watch: true,
21-
postcss: [autoprefixer],
2211
plugins: [
2312
new webpack.DefinePlugin({
2413
'process.env.NODE_ENV': JSON.stringify('test')

0 commit comments

Comments
 (0)