Skip to content

Commit

Permalink
add transpilation step
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs committed Jan 9, 2017
1 parent 9d8d9dd commit 3b286be
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"production": {
"presets": [
"latest"
],
"plugins": [
"add-module-exports",
"transform-es2015-modules-amd"
]
},
"development": {
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules

# main app
static/src/stylesheets
static/transpiled
static/vendor/javascripts
static/src/javascripts-legacy/projects/common/utils/atob.js
static/src/javascripts-legacy/projects/common/utils/picturefill.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ developer.properties
*-spec-runner.html

static/hash
static/transpiled
static/target
static/riffraff

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
"any-observable": "^0.2.0",
"autoprefixer": "^6.5.3",
"aws-sdk": "~2.0.0-rc4",
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-es2015-modules-amd": "^6.18.0",
"babel-preset-env": "^1.1.4",
"babel-preset-latest": "^6.16.0",
"browser-sync": "^2.8.2",
Expand Down
12 changes: 12 additions & 0 deletions tools/__tasks__/compile/javascript/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const execa = require('execa');

const { src, transpiled } = require('../../config').paths;

module.exports = {
description: 'Transpile',
task: () => execa('babel', [`${src}/javascripts`, '--out-dir', `${transpiled}/javascripts`, '--ignore', 'eslintrc.js'], {
env: {
BABEL_ENV: 'production',
},
}),
};
3 changes: 2 additions & 1 deletion tools/__tasks__/compile/javascript/clean.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const rimraf = require('rimraf');

const { target, hash } = require('../../config').paths;
const { target, hash, transpiled } = require('../../config').paths;

module.exports = {
description: 'Clear JS build artefacts',
task: () => {
rimraf.sync(path.resolve(target, 'javascripts'));
rimraf.sync(path.resolve(transpiled, 'javascripts'));
rimraf.sync(path.resolve(hash, 'javascripts'));
},
};
15 changes: 14 additions & 1 deletion tools/__tasks__/compile/javascript/copy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const cpy = require('cpy');

const { vendor, target, hash } = require('../../config').paths;
const { src, vendor, target, hash, transpiled } = require('../../config').paths;

module.exports = {
description: 'Copy 3rd JS party libraries',
Expand All @@ -23,5 +23,18 @@ module.exports = {
parents: true,
nodir: true,
}),
// copy the legacy (untranspiled es5) code to `transpiled`.
// once that directory has been converted, this won't be needed.
cpy(['**/*'], path.resolve(transpiled, 'javascripts'), {
cwd: path.resolve(src, 'javascripts-legacy'),
parents: true,
nodir: true,
}),
cpy(['**/*'], path.resolve(transpiled, 'javascripts'), {
cwd: path.resolve(src, 'javascripts'),
parents: true,
nodir: true,
ignore: '*.js',
}),
]),
};
1 change: 1 addition & 0 deletions tools/__tasks__/compile/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
require('./clean'),
require('../inline-svgs'),
require('./copy'),
require('./babel'),
require('./rjs'),
require('./rjs--webpack'),
require('./webpack'),
Expand Down
2 changes: 1 addition & 1 deletion tools/__tasks__/compile/javascript/rjs.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-expressions */
({
baseUrl: '../../../../static/src/javascripts',
baseUrl: '../../../../static/transpiled/javascripts',
paths: {
admin: 'projects/admin',
common: 'projects/common',
Expand Down
1 change: 1 addition & 0 deletions tools/__tasks__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
module.exports = {
paths: {
target: path.join(__dirname, '../', '../', 'static', 'target'),
transpiled: path.join(__dirname, '../', '../', 'static', 'transpiled'),
hash: path.join(__dirname, '../', '../', 'static', 'hash'),
src: path.join(__dirname, '../', '../', 'static', 'src'),
public: path.join(__dirname, '../', '../', 'static', 'public'),
Expand Down
11 changes: 11 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
process.env.BABEL_ENV = 'production';

const webpack = require('webpack');
const path = require('path');
Expand All @@ -8,6 +9,7 @@ module.exports = {
resolve: {
modulesDirectories: [
'static/src/javascripts',
'static/src/javascripts-legacy',
'static/vendor/javascripts',
],
alias: {
Expand Down Expand Up @@ -55,4 +57,13 @@ module.exports = {
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components|javascripts-legacy|components|vendor)/,
loader: 'babel-loader',
},
],
},
};
97 changes: 50 additions & 47 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,28 @@ aws4@^1.2.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.5.0.tgz#0a29ffb79c31c9e712eeb087e8e7a64b4a56d755"

babel-code-frame@^6.16.0:
version "6.16.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.16.0.tgz#f90e60da0862909d3ce098733b5d3987c97cb8de"
babel-cli@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.18.0.tgz#92117f341add9dead90f6fa7d0a97c0cc08ec186"
dependencies:
chalk "^1.1.0"
esutils "^2.0.2"
js-tokens "^2.0.0"
babel-core "^6.18.0"
babel-polyfill "^6.16.0"
babel-register "^6.18.0"
babel-runtime "^6.9.0"
commander "^2.8.1"
convert-source-map "^1.1.0"
fs-readdir-recursive "^1.0.0"
glob "^5.0.5"
lodash "^4.2.0"
output-file-sync "^1.1.0"
path-is-absolute "^1.0.0"
slash "^1.0.0"
source-map "^0.5.0"
v8flags "^2.0.10"
optionalDependencies:
chokidar "^1.0.0"

babel-code-frame@^6.20.0:
babel-code-frame@^6.16.0, babel-code-frame@^6.20.0:
version "6.20.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.20.0.tgz#b968f839090f9a8bc6d41938fb96cb84f7387b26"
dependencies:
Expand Down Expand Up @@ -441,6 +454,10 @@ babel-messages@^6.8.0:
dependencies:
babel-runtime "^6.0.0"

babel-plugin-add-module-exports@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz#9ae9a1f4a8dc67f0cdec4f4aeda1e43a5ff65e25"

babel-plugin-check-es2015-constants@^6.3.13:
version "6.8.0"
resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.8.0.tgz#dbf024c32ed37bfda8dee1e76da02386a8d26fe7"
Expand Down Expand Up @@ -659,6 +676,14 @@ babel-plugin-transform-strict-mode@^6.18.0:
babel-runtime "^6.0.0"
babel-types "^6.18.0"

babel-polyfill@^6.16.0:
version "6.20.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.20.0.tgz#de4a371006139e20990aac0be367d398331204e7"
dependencies:
babel-runtime "^6.20.0"
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

babel-preset-env@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.1.4.tgz#d876f9fcff5fe0612db3dcbc0c87503b41d4873f"
Expand Down Expand Up @@ -754,14 +779,7 @@ babel-register@^6.18.0:
mkdirp "^0.5.1"
source-map-support "^0.4.2"

babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.9.0, babel-runtime@^6.9.1:
version "6.11.6"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.11.6.tgz#6db707fef2d49c49bfa3cb64efdb436b518b8222"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.9.5"

babel-runtime@^6.20.0:
babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.20.0, babel-runtime@^6.9.0:
version "6.20.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.20.0.tgz#87300bdcf4cd770f09bf0048c64204e17806d16f"
dependencies:
Expand All @@ -778,21 +796,7 @@ babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-te
babylon "^6.11.0"
lodash "^4.2.0"

babel-traverse@^6.16.0, babel-traverse@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.18.0.tgz#5aeaa980baed2a07c8c47329cd90c3b90c80f05e"
dependencies:
babel-code-frame "^6.16.0"
babel-messages "^6.8.0"
babel-runtime "^6.9.0"
babel-types "^6.18.0"
babylon "^6.11.0"
debug "^2.2.0"
globals "^9.0.0"
invariant "^2.2.0"
lodash "^4.2.0"

babel-traverse@^6.21.0:
babel-traverse@^6.16.0, babel-traverse@^6.18.0, babel-traverse@^6.21.0:
version "6.21.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.21.0.tgz#69c6365804f1a4f69eb1213f85b00a818b8c21ad"
dependencies:
Expand All @@ -806,16 +810,7 @@ babel-traverse@^6.21.0:
invariant "^2.2.0"
lodash "^4.2.0"

babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.8.0, babel-types@^6.9.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.18.0.tgz#1f7d5a73474c59eb9151b2417bbff4e4fce7c3f8"
dependencies:
babel-runtime "^6.9.1"
esutils "^2.0.2"
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babel-types@^6.21.0:
babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.21.0, babel-types@^6.8.0, babel-types@^6.9.0:
version "6.21.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.21.0.tgz#314b92168891ef6d3806b7f7a917fdf87c11a4b2"
dependencies:
Expand Down Expand Up @@ -2444,6 +2439,10 @@ fs-extra@0.30.0, fs-extra@^0.30.0, fs-extra@~0.30.0:
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-readdir-recursive@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#8cd1745c8b4f8a29c8caec392476921ba195f560"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -2582,7 +2581,7 @@ glob@^4.3.1:
minimatch "^2.0.1"
once "^1.3.0"

glob@^5.0.15, glob@~5.0.0:
glob@^5.0.15, glob@^5.0.5, glob@~5.0.0:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
dependencies:
Expand Down Expand Up @@ -2709,7 +2708,7 @@ gonzales-pe@3.4.4:
dependencies:
minimist "1.1.x"

graceful-fs@4.X, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
graceful-fs@4.X, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
version "4.1.9"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.9.tgz#baacba37d19d11f9d146d3578bc99958c3787e29"

Expand Down Expand Up @@ -4381,6 +4380,14 @@ osenv@^0.1.3:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

output-file-sync@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-1.1.2.tgz#d0a33eefe61a205facb90092e826598d5245ce76"
dependencies:
graceful-fs "^4.1.4"
mkdirp "^0.5.1"
object-assign "^4.1.0"

pako@~0.2.0:
version "0.2.9"
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
Expand Down Expand Up @@ -5034,10 +5041,6 @@ regenerator-runtime@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.1.tgz#257f41961ce44558b18f7814af48c17559f9faeb"

regenerator-runtime@^0.9.5:
version "0.9.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.5.tgz#403d6d40a4bdff9c330dd9392dcbb2d9a8bba1fc"

regex-cache@^0.4.2:
version "0.4.3"
resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145"
Expand Down Expand Up @@ -5975,7 +5978,7 @@ utils-merge@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"

v8flags@^2.0.2:
v8flags@^2.0.10, v8flags@^2.0.2:
version "2.0.11"
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.0.11.tgz#bca8f30f0d6d60612cc2c00641e6962d42ae6881"
dependencies:
Expand Down

0 comments on commit 3b286be

Please sign in to comment.