aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Gębala <maarcin.gebala@gmail.com>2017-03-16 14:57:29 +0100
committerMarcin Gębala <maarcin.gebala@gmail.com>2017-03-17 15:39:43 +0100
commit6bf92afd602f6d04ecf977bf6f77325166aab034 (patch)
treea4e3c6668c31ef7c9ec695e355ab37a18fa88657
parent5248d043458e52c5728751d23019bd9ffc1e2659 (diff)
downloadsaleor-frontend-6bf92afd602f6d04ecf977bf6f77325166aab034.tar.gz
saleor-frontend-6bf92afd602f6d04ecf977bf6f77325166aab034.tar.bz2
saleor-frontend-6bf92afd602f6d04ecf977bf6f77325166aab034.zip
Add separate webpack config for production
-rw-r--r--.travis.yml2
-rw-r--r--circle.yml2
-rw-r--r--docs/deploy.rst2
-rw-r--r--docs/development.rst4
-rw-r--r--package.json1
-rw-r--r--webpack.config.js5
-rw-r--r--webpack.production.config.js54
7 files changed, 64 insertions, 6 deletions
diff --git a/.travis.yml b/.travis.yml
index 584e9355..3051a0f0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,7 +21,7 @@ install:
- nvm install 6
- yarn
- yarn add --force node-sass # force our way around https://github.com/yarnpkg/yarn/issues/1981
- - yarn run build-assets
+ - yarn run build-assets:prod
script:
- tox
env:
diff --git a/circle.yml b/circle.yml
index 1a131874..0db89c0b 100644
--- a/circle.yml
+++ b/circle.yml
@@ -16,7 +16,7 @@ dependencies:
- yarn add --force node-sass # force our way around https://github.com/yarnpkg/yarn/issues/1981
- pip install -r requirements.txt
override:
- - yarn run build-assets --production
+ - yarn run build-assets:prod --production
- ./manage.py collectstatic --no-input
- sed -i.bak "s#'dev'#'$(git describe --tags)'#" saleor/__init__.py
post:
diff --git a/docs/deploy.rst b/docs/deploy.rst
index e8cdbe3b..642673b7 100644
--- a/docs/deploy.rst
+++ b/docs/deploy.rst
@@ -12,7 +12,7 @@ Before building the image make sure you have all of the front-end assets prepare
.. code-block:: bash
- $ yarn run build-assets
+ $ yarn run build-assets:prod
$ python manage.py collectstatic
Then use Docker to build the image:
diff --git a/docs/development.rst b/docs/development.rst
index e5a41cfb..af4f15c4 100644
--- a/docs/development.rst
+++ b/docs/development.rst
@@ -29,7 +29,7 @@ To run webpack in *watch* mode run:
.. code-block:: bash
- $ npm start
+ $ yarn start
.. warning::
@@ -38,7 +38,7 @@ To run webpack in *watch* mode run:
.. code-block:: bash
- $ npm run build-assets
+ $ yarn run build-assets:prod
Working with backend code
diff --git a/package.json b/package.json
index ae605ee6..fe13df41 100644
--- a/package.json
+++ b/package.json
@@ -89,6 +89,7 @@
},
"scripts": {
"build-assets": "node ./node_modules/webpack/bin/webpack.js -p",
+ "build-assets:prod": "NODE_ENV=production node ./node_modules/webpack/bin/webpack.js --config webpack.production.config.js -p",
"heroku-postbuild": "yarn add --force node-sass && yarn run build-assets",
"start": "UV_THREADPOOL_SIZE=8 node ./node_modules/webpack/bin/webpack.js -d --watch"
}
diff --git a/webpack.config.js b/webpack.config.js
index 5eb54194..5840f5f1 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -24,6 +24,8 @@ var environmentPlugin = new webpack.DefinePlugin({
}
});
+var uglifyJSPlugin = new webpack.optimize.UglifyJsPlugin();
+
var providePlugin = new webpack.ProvidePlugin({
$: 'jquery',
'_': 'underscore',
@@ -89,7 +91,8 @@ var config = {
environmentPlugin,
extractTextPlugin,
occurenceOrderPlugin,
- providePlugin
+ providePlugin,
+ uglifyJSPlugin
],
postcss: function() {
return [autoprefixer];
diff --git a/webpack.production.config.js b/webpack.production.config.js
new file mode 100644
index 00000000..565f6730
--- /dev/null
+++ b/webpack.production.config.js
@@ -0,0 +1,54 @@
+var BundleTracker = require('webpack-bundle-tracker');
+var ExtractTextPlugin = require('extract-text-webpack-plugin');
+var path = require('path');
+var webpack = require('webpack');
+var config = require('./webpack.config');
+
+var resolve = path.resolve.bind(path, __dirname);
+
+var bundleTrackerPlugin = new BundleTracker({
+ filename: 'webpack-bundle.json'
+});
+
+var commonsChunkPlugin = new webpack.optimize.CommonsChunkPlugin({
+ names: 'vendor'
+});
+
+var extractTextPlugin = new ExtractTextPlugin('[name].css');
+
+var occurenceOrderPlugin = new webpack.optimize.OccurenceOrderPlugin();
+
+var environmentPlugin = new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
+ }
+});
+
+var uglifyJSPlugin = new webpack.optimize.UglifyJsPlugin();
+
+var providePlugin = new webpack.ProvidePlugin({
+ $: 'jquery',
+ '_': 'underscore',
+ jQuery: 'jquery',
+ 'window.jQuery': 'jquery',
+ 'Tether': 'tether',
+ 'window.Tether': 'tether'
+});
+
+config.output = {
+ path: resolve('saleor/static/assets/'),
+ filename: '[name].js',
+ publicPath: '/'
+};
+
+config.plugins = [
+ bundleTrackerPlugin,
+ commonsChunkPlugin,
+ environmentPlugin,
+ extractTextPlugin,
+ occurenceOrderPlugin,
+ providePlugin,
+ uglifyJSPlugin
+];
+
+module.exports = config;