Skip to content

Commit 32f048b

Browse files
author
Marek Rozmus
committed
Update example for dev and sandbox
1 parent 14f3d20 commit 32f048b

File tree

5 files changed

+129
-16
lines changed

5 files changed

+129
-16
lines changed

examples/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"scripts": {
2525
"predeploy": "webpack --mode production",
2626
"start": "webpack-dev-server",
27+
"dev": "webpack-dev-server --config webpack.config.dev.js",
2728
"deploy": "gh-pages -d dist"
2829
},
2930
"devDependencies": {
@@ -53,6 +54,7 @@
5354
"webpack-dev-server": "^3.8.0"
5455
},
5556
"dependencies": {
57+
"@sandstreamdev/react-swipeable-list": "^0.2.1",
5658
"react": "^16.9.0",
5759
"react-dom": "^16.9.0"
5860
}

examples/src/App.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { useState } from 'react';
2-
import { SwipeableList, SwipeableListItem } from 'react-swipeable-list';
2+
import {
3+
SwipeableList,
4+
SwipeableListItem
5+
} from '@sandstreamdev/react-swipeable-list';
6+
import '@sandstreamdev/react-swipeable-list/dist/styles.css';
37

48
import ListItem from './ComplexListItem';
59
import ComplexItemContent from './ComplexItemContent';

examples/webpack.config.dev.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
var HtmlWebpackPlugin = require('html-webpack-plugin');
2+
var path = require('path');
3+
var CssLoaderUtils = require('css-loader/dist/utils');
4+
5+
const babelLoaderOptions = {
6+
presets: ['@babel/env', '@babel/react'],
7+
plugins: ['@babel/plugin-proposal-class-properties']
8+
};
9+
10+
module.exports = {
11+
devServer: {
12+
port: 3000,
13+
open: true,
14+
inline: true,
15+
hot: true,
16+
watchOptions: {
17+
ignored: /node_modules/
18+
},
19+
historyApiFallback: true
20+
},
21+
module: {
22+
rules: [
23+
{
24+
test: /\.js$/,
25+
exclude: /node_modules/,
26+
use: {
27+
loader: 'babel-loader',
28+
options: babelLoaderOptions
29+
}
30+
},
31+
{
32+
test: /\.css$/i,
33+
use: [
34+
{ loader: 'style-loader' },
35+
{
36+
loader: 'css-loader',
37+
options: {
38+
modules: {
39+
localIdentName: '[name]_[local]__[hash:base64:5]_',
40+
getLocalIdent: (
41+
loaderContext,
42+
localIdentName,
43+
localName,
44+
options
45+
) => {
46+
if (loaderContext.resourcePath.includes('node_modules')) {
47+
return localName;
48+
}
49+
return CssLoaderUtils.getLocalIdent(
50+
loaderContext,
51+
localIdentName,
52+
localName,
53+
options
54+
);
55+
}
56+
}
57+
}
58+
}
59+
]
60+
},
61+
{
62+
test: /\.svg$/,
63+
use: [
64+
{
65+
loader: 'babel-loader'
66+
},
67+
{
68+
loader: 'react-svg-loader'
69+
}
70+
]
71+
}
72+
]
73+
},
74+
plugins: [
75+
new HtmlWebpackPlugin({
76+
template: './src/index.html',
77+
filename: './index.html'
78+
})
79+
],
80+
resolve: {
81+
alias: {
82+
// replace with any css - cannot ignore this import
83+
'@sandstreamdev/react-swipeable-list/dist/styles.css': path.join(
84+
__dirname,
85+
'src',
86+
'app.css'
87+
),
88+
// to import module sources
89+
'@sandstreamdev/react-swipeable-list': path.join(__dirname, '..', 'src'),
90+
// to make the module use same react as example
91+
// (otherwise even if same version is in module sources used
92+
// we get error about duplicated react and cannot use hooks)
93+
react: path.resolve(__dirname, 'node_modules', 'react'),
94+
'prop-types': path.resolve(__dirname, 'node_modules', 'prop-types')
95+
},
96+
extensions: ['.js']
97+
}
98+
};

examples/webpack.config.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var HtmlWebpackPlugin = require('html-webpack-plugin');
2-
var path = require('path');
2+
var CssLoaderUtils = require('css-loader/dist/utils');
33

44
const babelLoaderOptions = {
55
presets: ['@babel/env', '@babel/react'],
@@ -35,7 +35,23 @@ module.exports = {
3535
loader: 'css-loader',
3636
options: {
3737
modules: {
38-
localIdentName: '[name]_[local]__[hash:base64:5]_'
38+
localIdentName: '[name]_[local]__[hash:base64:5]_',
39+
getLocalIdent: (
40+
loaderContext,
41+
localIdentName,
42+
localName,
43+
options
44+
) => {
45+
if (loaderContext.resourcePath.includes('node_modules')) {
46+
return localName;
47+
}
48+
return CssLoaderUtils.getLocalIdent(
49+
loaderContext,
50+
localIdentName,
51+
localName,
52+
options
53+
);
54+
}
3955
}
4056
}
4157
}
@@ -59,17 +75,5 @@ module.exports = {
5975
template: './src/index.html',
6076
filename: './index.html'
6177
})
62-
],
63-
resolve: {
64-
alias: {
65-
// to import module sources
66-
'react-swipeable-list': path.join(__dirname, '..', 'src'),
67-
// to make the module use same react as example
68-
// (otherwise even if same version is in module sources used
69-
// we get error about duplicated react and cannot use hooks)
70-
react: path.resolve(__dirname, 'node_modules', 'react'),
71-
'prop-types': path.resolve(__dirname, 'node_modules', 'prop-types')
72-
},
73-
extensions: ['.js']
74-
}
78+
]
7579
};

0 commit comments

Comments
 (0)