diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ff325a --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.pyc +*~ +dist +build +django_webpacker.egg-info/ +sample_project/node_modules/ +sample_project/static/webpack_bundles/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6fe59e0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python + +python: + - "3.4" + +install: + - python setup.py install + - pip install coveralls + +script: + - coverage run --source=testapp sample_project/manage.py test + +after_success: + coveralls \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..462d55a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.rst +recursive-include django_webpacker/management * \ No newline at end of file diff --git a/README.rst b/README.rst index 2bcc558..1d17917 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,23 @@ django-webpacker's documentation: ===================================== -#badges +.. image:: https://readthedocs.org/projects/django-webpacker/badge/?version=latest + :target: http://django-webpacker.readthedocs.io/en/latest/?badge=latest + :alt: Documentation Status + +.. image:: https://coveralls.io/repos/github/MicroPyramid/django-webpacker/badge.svg?branch=master + :target: https://coveralls.io/github/MicroPyramid/django-webpacker?branch=master + +.. image:: https://travis-ci.org/MicroPyramid/django-webpacker.svg?branch=master + :target: https://travis-ci.org/MicroPyramid/django-webpacker + +.. image:: https://landscape.io/github/MicroPyramid/django-webpacker/master/landscape.svg?style=flat + :target: https://landscape.io/github/MicroPyramid/django-webpacker/master + :alt: Code Health + +.. image:: https://img.shields.io/github/license/micropyramid/django-webpacker.svg + :target: https://pypi.python.org/pypi/django-webpacker/ + Introduction: ============= diff --git a/django_webpacker/management/commands/__init__.py b/django_webpacker/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/source/index.rst b/docs/source/index.rst index bfde824..2eca6ad 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,8 +1,6 @@ django-webpacker's documentation: ===================================== -#badges - Introduction: ============= diff --git a/sample_project/manage.py b/sample_project/manage.py new file mode 100755 index 0000000..db62fa4 --- /dev/null +++ b/sample_project/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/sample_project/package.json b/sample_project/package.json new file mode 100644 index 0000000..2e22c42 --- /dev/null +++ b/sample_project/package.json @@ -0,0 +1,36 @@ +{ + "name": "sample_project", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "babel": "^6.23.0", + "babel-core": "^6.24.0", + "babel-loader": "^6.4.1", + "css-loader": "^0.28.0", + "extract-text-webpack-plugin": "^2.1.0", + "file-loader": "^0.11.1", + "html-webpack-inline-source-plugin": "0.0.7", + "html-webpack-plugin": "^2.28.0", + "image-webpack-loader": "^3.3.0", + "less-loader": "^4.0.3", + "node-sass": "^4.5.2", + "react": "^15.4.2", + "react-hot-loader": "^1.3.1", + "sass-loader": "^6.0.3", + "script-loader": "^0.7.0", + "style-loader": "^0.16.1", + "webpack": "^2.3.3", + "webpack-bundle-tracker": "^0.2.0", + "webpack-dev-server": "^2.4.2" + }, + "dependencies": { + "imports-loader": "^0.7.1", + "jquery": "^3.2.1" + } +} diff --git a/sample_project/requirements.txt b/sample_project/requirements.txt new file mode 100644 index 0000000..6abbe5d --- /dev/null +++ b/sample_project/requirements.txt @@ -0,0 +1,3 @@ +boto==2.46.1 +Django==1.9.13 +django-webpacker==0.1.1 diff --git a/sample_project/sample_project/__init__.py b/sample_project/sample_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sample_project/sample_project/settings.py b/sample_project/sample_project/settings.py new file mode 100644 index 0000000..3f34b58 --- /dev/null +++ b/sample_project/sample_project/settings.py @@ -0,0 +1,86 @@ +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +SECRET_KEY = '8&=h22)%v2_ii66p30-6=3_v%(&ujs83q=l1@m^fd6#t&00tr&' + +DEBUG = True + +ALLOWED_HOSTS = [] + + + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django_webpacker', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'sample_project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'sample_project.wsgi.application' + + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +STATIC_URL = '/static/' + + +STATIC_URL = '/static/' + +STATICFILES_DIRS = (BASE_DIR + '/static',) + + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + # other finders.. +) + +WEB_PACK_FILES = [ + {'html_file_name': 'templates/index.html', + 'webpack_js': 'index', + }, + {'html_file_name': 'templates/login.html', + 'webpack_js': 'login', + }, +] + +ENABLE_DJANGO_WEBPACK_S3_STORAGES = False +AWS_BUCKET_NAME = '' \ No newline at end of file diff --git a/sample_project/sample_project/urls.py b/sample_project/sample_project/urls.py new file mode 100644 index 0000000..907acdd --- /dev/null +++ b/sample_project/sample_project/urls.py @@ -0,0 +1,24 @@ +"""sample_project URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.10/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin +from testapp.views import * + +urlpatterns = [ + url(r'^admin/', admin.site.urls), + url(r'^$', index), + url(r'^login/$', login_page, name="login_page"), +] diff --git a/sample_project/sample_project/wsgi.py b/sample_project/sample_project/wsgi.py new file mode 100644 index 0000000..4a9ed68 --- /dev/null +++ b/sample_project/sample_project/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sample_project project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings") + +application = get_wsgi_application() diff --git a/sample_project/static/css/login.css b/sample_project/static/css/login.css new file mode 100644 index 0000000..543eada --- /dev/null +++ b/sample_project/static/css/login.css @@ -0,0 +1,6 @@ +body{ + color: #ddd; +} +a{ + color: blue; +} \ No newline at end of file diff --git a/sample_project/static/css/main.css b/sample_project/static/css/main.css new file mode 100644 index 0000000..bbd9d49 --- /dev/null +++ b/sample_project/static/css/main.css @@ -0,0 +1,6 @@ +body{ + color: #ddd; +} +a{ + color: red; +} \ No newline at end of file diff --git a/sample_project/static/js/login.js b/sample_project/static/js/login.js new file mode 100644 index 0000000..df19f2f --- /dev/null +++ b/sample_project/static/js/login.js @@ -0,0 +1,3 @@ +$('#login').click(function(e){ + alert("click on login 123") +}) \ No newline at end of file diff --git a/sample_project/static/js/main.js b/sample_project/static/js/main.js new file mode 100644 index 0000000..0293c98 --- /dev/null +++ b/sample_project/static/js/main.js @@ -0,0 +1,3 @@ +$('#hello_world').click(function(e){ + alert("click on hello world 123") +}) \ No newline at end of file diff --git a/sample_project/templates/index.html b/sample_project/templates/index.html new file mode 100644 index 0000000..e6e7e18 --- /dev/null +++ b/sample_project/templates/index.html @@ -0,0 +1,11 @@ + + + + Hello + + + + Hello world + + + diff --git a/sample_project/templates/login.html b/sample_project/templates/login.html new file mode 100644 index 0000000..a0c17c8 --- /dev/null +++ b/sample_project/templates/login.html @@ -0,0 +1,11 @@ + + + + Hello + + + + login + + + diff --git a/sample_project/testapp/__init__.py b/sample_project/testapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sample_project/testapp/apps.py b/sample_project/testapp/apps.py new file mode 100644 index 0000000..9806af7 --- /dev/null +++ b/sample_project/testapp/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestappConfig(AppConfig): + name = 'testapp' diff --git a/sample_project/testapp/migrations/__init__.py b/sample_project/testapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sample_project/testapp/tests.py b/sample_project/testapp/tests.py new file mode 100644 index 0000000..2d3f8d2 --- /dev/null +++ b/sample_project/testapp/tests.py @@ -0,0 +1,11 @@ +from django.core.management import call_command +from django.test import TestCase + + +class CommandsTestCase(TestCase): + def test_mycommand(self): + " Test my custom command." + + args = [] + opts = {} + call_command('compress_css_js_files', *args, **opts) diff --git a/sample_project/testapp/views.py b/sample_project/testapp/views.py new file mode 100644 index 0000000..feeb4a6 --- /dev/null +++ b/sample_project/testapp/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render + +# Create your views here. + +def index(request): + return render(request, 'index.html') + + +def login_page(request): + return render(request, 'login.html') \ No newline at end of file diff --git a/sample_project/webpack-stats.json b/sample_project/webpack-stats.json new file mode 100644 index 0000000..19a79e3 --- /dev/null +++ b/sample_project/webpack-stats.json @@ -0,0 +1 @@ +{"status":"done","chunks":{"index":[{"name":"index-eae3e24342216ce07d17.js","path":"/home/nikhila/mp_projs/django_packer/django_web_packer/sample_project/static/webpack_bundles/index-eae3e24342216ce07d17.js"},{"name":"index-eae3e24342216ce07d17.css","path":"/home/nikhila/mp_projs/django_packer/django_web_packer/sample_project/static/webpack_bundles/index-eae3e24342216ce07d17.css"}],"login":[{"name":"login-eae3e24342216ce07d17.js","path":"/home/nikhila/mp_projs/django_packer/django_web_packer/sample_project/static/webpack_bundles/login-eae3e24342216ce07d17.js"},{"name":"login-eae3e24342216ce07d17.css","path":"/home/nikhila/mp_projs/django_packer/django_web_packer/sample_project/static/webpack_bundles/login-eae3e24342216ce07d17.css"}]}} \ No newline at end of file diff --git a/sample_project/webpack.config.js b/sample_project/webpack.config.js new file mode 100644 index 0000000..9e7ace0 --- /dev/null +++ b/sample_project/webpack.config.js @@ -0,0 +1,61 @@ +var path = require('path'); +var webpack = require('webpack'); +var BundleTracker = require('webpack-bundle-tracker'); +var ExtractTextPlugin = require("extract-text-webpack-plugin"); + + + +module.exports = { + context: __dirname, + entry: { + index: './webpack_js/index', + login: './webpack_js/login', + }, + output: { + path: path.resolve('./static/webpack_bundles/'), + filename: "[name]-[hash].js" + }, + module: { + loaders: [ + // Extract css files + { + test: /\.js$|\.jsx$/, + loader: 'babel-loader', + exclude: /node_modules/ + }, + { + test: /\.css$/, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }) + }, + // Optionally extract less files + // or any other compile-to-css language + { + test: /\.less$/i, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!less-loader" }) + }, + { + test: /\.scss$/, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!sass-loader!image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false" }) + }, + {test: /\.(jpe?g|png|gif|svg)$/i, loaders: [ + 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]', + 'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false' + ]}, + // Optionally extract less files + // or any other compile-to-css language + // You could also use other loaders the same way. I. e. the autoprefixer-loader + ] + }, + plugins: [ + new webpack.ProvidePlugin({ + $: "jquery", + jQuery: "jquery", + "window.jQuery": "jquery" + }), + + new BundleTracker({filename: './webpack-stats.json'}), + new ExtractTextPlugin({ + filename: "[name]-[hash].css", + allChunks: true + }), ] +} \ No newline at end of file diff --git a/sample_project/webpack_js/index.js b/sample_project/webpack_js/index.js new file mode 100644 index 0000000..f48afac --- /dev/null +++ b/sample_project/webpack_js/index.js @@ -0,0 +1,3 @@ +require("../static/js/main.js") + +require("../static/css/main.css") diff --git a/sample_project/webpack_js/login.js b/sample_project/webpack_js/login.js new file mode 100644 index 0000000..2e7d7ea --- /dev/null +++ b/sample_project/webpack_js/login.js @@ -0,0 +1,3 @@ +require("../static/js/login.js") + +require("../static/css/login.css") diff --git a/setup.py b/setup.py index 1076895..672cd0e 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,8 @@ setup( name='django-webpacker', - version='0.1', - packages=find_packages(exclude=['tests', 'tests.*']), + version='0.1.1', + packages=find_packages(exclude=[]), include_package_data=True, description='A django compressor tool which bundles css, js files to single css, js file with webpack', long_description=README, @@ -46,6 +46,6 @@ ], install_requires=[ "Django>=1.6.0,<1.10", - 'boto', + 'boto' ], ) diff --git a/webpack.config.js b/webpack.config.js index 586c87c..ca1da12 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,6 @@ var BundleTracker = require('webpack-bundle-tracker'); var ExtractTextPlugin = require("extract-text-webpack-plugin"); - module.exports = { context: __dirname, entry: { @@ -16,45 +15,42 @@ module.exports = { filename: "[name]-[hash].js" }, module: { - loaders: [ - // Extract css files -{ - test: /\.js$|\.jsx$/, - loader: 'babel-loader', - exclude: /node_modules/ - }, - { - test: /\.css$/, - loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }) - }, - // Optionally extract less files - // or any other compile-to-css language - { - test: /\.less$/i, - loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!less-loader" }) - }, - { - test: /\.scss$/, - loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!sass-loader!image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false" }) - }, - {test: /\.(jpe?g|png|gif|svg)$/i, loaders: [ - 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]', - 'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false' - ]}, - // Optionally extract less files - // or any other compile-to-css language - // You could also use other loaders the same way. I. e. the autoprefixer-loader - ] + loaders: [ + // Extract css files + { + test: /\.js$|\.jsx$/, + loader: 'babel-loader', + exclude: /node_modules/ + }, + { + test: /\.css$/, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }) + }, + // Optionally extract less files + // or any other compile-to-css language + { + test: /\.less$/i, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!less-loader" }) + }, + { + test: /\.scss$/, + loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: "css-loader!sass-loader!image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false" }) + }, + {test: /\.(jpe?g|png|gif|svg)$/i, loaders: [ + 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]', + 'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false' + ]}, + // Optionally extract less files + // or any other compile-to-css language + // You could also use other loaders the same way. I. e. the autoprefixer-loader + ] }, - externals: { - }, plugins: [ - new webpack.ProvidePlugin({ - $: "jquery", - jQuery: "jquery", - "window.jQuery": "jquery" - }), - + new webpack.ProvidePlugin({ + $: "jquery", + jQuery: "jquery", + "window.jQuery": "jquery" + }), new BundleTracker({filename: './webpack-stats.json'}), new ExtractTextPlugin({ filename: "[name]-[hash].css",