Resolve "Replace Gulp with Webpack"
This commit is contained in:
parent
16230a11f3
commit
b28d42b97b
18 changed files with 1673 additions and 1863 deletions
|
|
@ -14,7 +14,7 @@ javascript build:
|
||||||
before_script:
|
before_script:
|
||||||
- npm install
|
- npm install
|
||||||
script:
|
script:
|
||||||
- npx gulp
|
- npm run build
|
||||||
|
|
||||||
python tests:
|
python tests:
|
||||||
services:
|
services:
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# See https://pre-commit.com for more information
|
|
||||||
# See https://pre-commit.com/hooks.html for more hooks
|
|
||||||
default_language_version:
|
|
||||||
python: python3.7
|
|
||||||
|
|
||||||
repos:
|
|
||||||
- repo: local
|
|
||||||
hooks:
|
|
||||||
- id: autoflake
|
|
||||||
name: autoflake
|
|
||||||
entry: autoflake
|
|
||||||
language: system
|
|
||||||
types: [python]
|
|
||||||
args: ["--in-place", "--remove-unused-variables"]
|
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v2.0.0
|
|
||||||
hooks:
|
|
||||||
- id: trailing-whitespace
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: check-yaml
|
|
||||||
- id: check-added-large-files
|
|
||||||
- id: pretty-format-json
|
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
|
||||||
rev: 19.3b0
|
|
||||||
hooks:
|
|
||||||
- id: black
|
|
||||||
args: [--line-length=90]
|
|
||||||
|
|
||||||
- repo: https://github.com/timothycrosley/isort
|
|
||||||
rev: 4.3.21-2
|
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
|
|
||||||
- repo: https://github.com/prettier/prettier
|
|
||||||
rev: 1.18.2
|
|
||||||
hooks:
|
|
||||||
- id: prettier
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
import path from 'path';
|
|
||||||
import del from 'del';
|
|
||||||
|
|
||||||
import { dest, parallel, series, src, watch as _watch } from 'gulp';
|
|
||||||
import concat from 'gulp-concat';
|
|
||||||
import globby from 'globby';
|
|
||||||
import sass from 'gulp-sass';
|
|
||||||
import babelify from 'babelify';
|
|
||||||
import browserify from 'browserify';
|
|
||||||
import source from 'vinyl-source-stream';
|
|
||||||
import buffer from 'vinyl-buffer';
|
|
||||||
|
|
||||||
const PROJECT_DIR = path.join('src', 'newsreader');
|
|
||||||
const STATIC_DIR = path.join(PROJECT_DIR, 'static');
|
|
||||||
const CSS_SUFFIX = 'css/';
|
|
||||||
const JS_SUFFIX = 'js/';
|
|
||||||
|
|
||||||
const SASS_DEST_DIR = path.join(STATIC_DIR, CSS_SUFFIX);
|
|
||||||
const JS_DEST_DIR = path.join(STATIC_DIR, JS_SUFFIX);
|
|
||||||
|
|
||||||
const SASS_DIR = path.join(PROJECT_DIR, 'scss');
|
|
||||||
const JS_DIR = path.join(PROJECT_DIR, 'js');
|
|
||||||
|
|
||||||
const clean = () => {
|
|
||||||
return del([`${STATIC_DIR}/${CSS_SUFFIX}/*.css`, `${STATIC_DIR}/${JS_SUFFIX}/*.js`]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const sassTask = () => {
|
|
||||||
return src(`${SASS_DIR}/index.scss`)
|
|
||||||
.pipe(sass().on('error', sass.logError))
|
|
||||||
.pipe(concat(`main.css`))
|
|
||||||
.pipe(dest(SASS_DEST_DIR));
|
|
||||||
};
|
|
||||||
|
|
||||||
const babelTask = () => {
|
|
||||||
const getDirName = filename => {
|
|
||||||
const fragments = filename.split('/');
|
|
||||||
|
|
||||||
return fragments[fragments.length - 2];
|
|
||||||
};
|
|
||||||
|
|
||||||
const promise = globby([`${JS_DIR}/pages/**/index.js`]).then(entries => {
|
|
||||||
entries.forEach(entry => {
|
|
||||||
const bundle = browserify({ entries: entry, debug: true });
|
|
||||||
const transpiledBundle = bundle.transform(babelify);
|
|
||||||
const bundleName = getDirName(entry);
|
|
||||||
|
|
||||||
return transpiledBundle
|
|
||||||
.bundle()
|
|
||||||
.pipe(source('index.js'))
|
|
||||||
.pipe(buffer())
|
|
||||||
.pipe(concat(`${bundleName}.js`))
|
|
||||||
.pipe(dest(JS_DEST_DIR));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.resolve(promise);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const watch = () => {
|
|
||||||
return _watch(
|
|
||||||
[`${PROJECT_DIR}/scss/**/*.scss`, `${PROJECT_DIR}/js/**/*.js`],
|
|
||||||
{ ignoreInitial: false },
|
|
||||||
done => {
|
|
||||||
series(clean, parallel(sassTask, babelTask))(done);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default series(clean, parallel(babelTask, sassTask));
|
|
||||||
3297
package-lock.json
generated
3297
package-lock.json
generated
File diff suppressed because it is too large
Load diff
24
package.json
24
package.json
|
|
@ -6,7 +6,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "npx prettier \"src/newsreader/js/**/*.js\" --check",
|
"lint": "npx prettier \"src/newsreader/js/**/*.js\" --check",
|
||||||
"format": "npx prettier \"src/newsreader/js/**/*.js\" --write",
|
"format": "npx prettier \"src/newsreader/js/**/*.js\" --write",
|
||||||
"watch": "npx gulp watch",
|
"build": "webpack --config webpack.dev.babel.js",
|
||||||
|
"build:prod": "webpack --config webpack.prod.babel.js",
|
||||||
|
"watch": "npx webpack --config webpack.dev.babel.js --watch",
|
||||||
"test": "npx jest",
|
"test": "npx jest",
|
||||||
"test:watch": "npm test -- --watch"
|
"test:watch": "npm test -- --watch"
|
||||||
},
|
},
|
||||||
|
|
@ -17,7 +19,6 @@
|
||||||
"author": "Sonny",
|
"author": "Sonny",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"globby": "^11.0.0",
|
|
||||||
"js-cookie": "^2.2.1",
|
"js-cookie": "^2.2.1",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"object-assign": "^4.1.1",
|
"object-assign": "^4.1.1",
|
||||||
|
|
@ -38,23 +39,22 @@
|
||||||
"@babel/register": "^7.7.7",
|
"@babel/register": "^7.7.7",
|
||||||
"@babel/runtime": "^7.7.7",
|
"@babel/runtime": "^7.7.7",
|
||||||
"babel-jest": "^24.9.0",
|
"babel-jest": "^24.9.0",
|
||||||
"babelify": "^10.0.0",
|
"babel-loader": "^8.1.0",
|
||||||
"browserify": "^16.5.0",
|
"clean-webpack-plugin": "^3.0.0",
|
||||||
"del": "^5.1.0",
|
"css-loader": "^3.4.2",
|
||||||
"fetch-mock": "^8.3.1",
|
"fetch-mock": "^8.3.1",
|
||||||
"gulp": "^4.0.2",
|
|
||||||
"gulp-babel": "^8.0.0",
|
|
||||||
"gulp-cli": "^2.2.0",
|
|
||||||
"gulp-concat": "^2.6.1",
|
|
||||||
"gulp-sass": "^4.0.2",
|
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
|
"mini-css-extract-plugin": "^0.9.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"node-sass": "^4.13.1",
|
"node-sass": "^4.13.1",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.12.0",
|
||||||
"redux-mock-store": "^1.5.4",
|
"redux-mock-store": "^1.5.4",
|
||||||
"vinyl-buffer": "^1.0.1",
|
"sass-loader": "^8.0.2",
|
||||||
"vinyl-source-stream": "^2.0.0"
|
"style-loader": "^1.1.3",
|
||||||
|
"webpack": "^4.42.1",
|
||||||
|
"webpack-cli": "^3.3.11",
|
||||||
|
"webpack-merge": "^4.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@ import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import App from './App.js';
|
import App from './App.js';
|
||||||
|
|
||||||
const content = document.getElementById('categories--page');
|
const page = document.getElementById('categories--page');
|
||||||
const dataScript = document.getElementById('categories-data');
|
|
||||||
const categories = JSON.parse(dataScript.textContent);
|
|
||||||
|
|
||||||
ReactDOM.render(<App categories={categories} />, content);
|
if (page) {
|
||||||
|
const dataScript = document.getElementById('categories-data');
|
||||||
|
const categories = JSON.parse(dataScript.textContent);
|
||||||
|
|
||||||
|
ReactDOM.render(<App categories={categories} />, page);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class PostModal extends React.Component {
|
||||||
className="button post__close-button"
|
className="button post__close-button"
|
||||||
onClick={() => this.props.unSelectPost()}
|
onClick={() => this.props.unSelectPost()}
|
||||||
>
|
>
|
||||||
Close <i class="gg-close"></i>
|
Close <i className="gg-close"></i>
|
||||||
</button>
|
</button>
|
||||||
<div className="post__header">
|
<div className="post__header">
|
||||||
<h1 className={titleClassName}>{`${post.title} `}</h1>
|
<h1 className={titleClassName}>{`${post.title} `}</h1>
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class FeedList extends React.Component {
|
||||||
return (
|
return (
|
||||||
<div className="post-message">
|
<div className="post-message">
|
||||||
<div className="post-message__block">
|
<div className="post-message__block">
|
||||||
<i class="gg-arrow-left" />
|
<i className="gg-arrow-left" />
|
||||||
<p className="post-message__text">Select an item to show its unread posts</p>
|
<p className="post-message__text">Select an item to show its unread posts</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@ import configureStore from './configureStore.js';
|
||||||
|
|
||||||
import App from './App.js';
|
import App from './App.js';
|
||||||
|
|
||||||
const content = document.getElementById('homepage--page');
|
const page = document.getElementById('homepage--page');
|
||||||
const store = configureStore();
|
|
||||||
|
|
||||||
ReactDOM.render(
|
if (page) {
|
||||||
<Provider store={store}>
|
const store = configureStore();
|
||||||
<App />
|
|
||||||
</Provider>,
|
ReactDOM.render(
|
||||||
content
|
<Provider store={store}>
|
||||||
);
|
<App />
|
||||||
|
</Provider>,
|
||||||
|
page
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@ import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import App from './App.js';
|
import App from './App.js';
|
||||||
|
|
||||||
const content = document.getElementById('rules--page');
|
const page = document.getElementById('rules--page');
|
||||||
const dataScript = document.getElementById('rules-data');
|
|
||||||
const rules = JSON.parse(dataScript.textContent);
|
|
||||||
|
|
||||||
ReactDOM.render(<App rules={rules} />, content);
|
if (page) {
|
||||||
|
const dataScript = document.getElementById('rules-data');
|
||||||
|
const rules = JSON.parse(dataScript.textContent);
|
||||||
|
|
||||||
|
ReactDOM.render(<App rules={rules} />, page);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
<script src="{% static 'js/rules.js' %}"></script>
|
|
||||||
|
{{ block.super }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -30,5 +30,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
<script src="{% static 'js/categories.js' %}"></script>
|
|
||||||
|
{{ block.super }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,3 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main id="homepage--page" class="main"></main>
|
<main id="homepage--page" class="main"></main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script src="{% static 'js/homepage.js' %}"></script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
|
||||||
BIN
src/newsreader/static/icons/rss.png
Normal file
BIN
src/newsreader/static/icons/rss.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
|
|
@ -4,6 +4,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Newreader</title>
|
<title>Newreader</title>
|
||||||
|
<link type="image/png" href="{% static 'icons/rss.png' %}" rel="shortcut icon" />
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<link href="{% static 'css/main.css' %}" rel="stylesheet" />
|
<link href="{% static 'css/main.css' %}" rel="stylesheet" />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -38,5 +39,7 @@
|
||||||
{% block content %}{% endblock content %}
|
{% block content %}{% endblock content %}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
{% block scripts %}{% endblock %}
|
{% block scripts %}
|
||||||
|
<script src="{% static 'js/main.bundle.js' %}"></script>
|
||||||
|
{% endblock %}
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
33
webpack.common.babel.js
Normal file
33
webpack.common.babel.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
||||||
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
entry: {
|
||||||
|
main: ['./src/newsreader/js/index.js', './src/newsreader/scss/index.scss'],
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: resolve(__dirname, 'src', 'newsreader', 'static', 'js'),
|
||||||
|
filename: '[name].bundle.js',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx)$/,
|
||||||
|
exclude: /(node_modules|bower_components)/,
|
||||||
|
use: { loader: 'babel-loader' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(sass|scss)$/,
|
||||||
|
use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader', 'sass-loader'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
filename: './src/newsreader/static/css/[name].css',
|
||||||
|
allChunks: true,
|
||||||
|
}),
|
||||||
|
new CleanWebpackPlugin(),
|
||||||
|
],
|
||||||
|
};
|
||||||
7
webpack.dev.babel.js
Normal file
7
webpack.dev.babel.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import merge from 'webpack-merge';
|
||||||
|
import common from './webpack.common.babel.js';
|
||||||
|
|
||||||
|
export default merge(common, {
|
||||||
|
mode: 'development',
|
||||||
|
devtool: 'inline-source-map',
|
||||||
|
});
|
||||||
4
webpack.prod.babel.js
Normal file
4
webpack.prod.babel.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import merge from 'webpack-merge';
|
||||||
|
import common from './webpack.common.babel.js';
|
||||||
|
|
||||||
|
export default merge(common, { mode: 'production' });
|
||||||
Loading…
Add table
Add a link
Reference in a new issue