From 7c691841f49f6c0216a4a8a036f1720e63d2390d Mon Sep 17 00:00:00 2001 From: Simon Legg Date: Mon, 19 Jun 2017 21:46:27 +0100 Subject: [PATCH] remove now unused old n-webpack code --- build/webpack/index.js | 25 -- .../lib/transforms/apply-simple-options.js | 12 - build/webpack/lib/transforms/babel.js | 86 ------- build/webpack/lib/transforms/base-js.js | 44 ---- build/webpack/lib/transforms/base-scss.js | 51 ---- build/webpack/lib/transforms/base.js | 18 -- build/webpack/lib/transforms/build-env.js | 18 -- build/webpack/lib/transforms/stats.js | 10 - build/webpack/webpack.config.js | 230 ------------------ 9 files changed, 494 deletions(-) delete mode 100644 build/webpack/index.js delete mode 100644 build/webpack/lib/transforms/apply-simple-options.js delete mode 100644 build/webpack/lib/transforms/babel.js delete mode 100644 build/webpack/lib/transforms/base-js.js delete mode 100644 build/webpack/lib/transforms/base-scss.js delete mode 100644 build/webpack/lib/transforms/base.js delete mode 100644 build/webpack/lib/transforms/build-env.js delete mode 100644 build/webpack/lib/transforms/stats.js delete mode 100644 build/webpack/webpack.config.js diff --git a/build/webpack/index.js b/build/webpack/index.js deleted file mode 100644 index f7f7c37a1..000000000 --- a/build/webpack/index.js +++ /dev/null @@ -1,25 +0,0 @@ -const clone = require('clone'); - -const transforms = [ - require('./lib/transforms/base'), - require('./lib/transforms/apply-simple-options'), - require('./lib/transforms/base-js'), - require('./lib/transforms/base-scss'), - require('./lib/transforms/babel'), - require('./lib/transforms/build-env'), - require('./lib/transforms/stats') -]; - -module.exports = (options) => { - options = clone(options); - options.ECMAScriptVersion = ('ECMAScriptVersion' in options) ? options.ECMAScriptVersion : 5; - const output = {}; - transforms.forEach(transform => { - transform(options, output); - }) - output.resolve.alias = output.resolve.alias = Object.assign(output.resolve.alias || {}, { - 'react': 'preact-compat', - 'react-dom': 'preact-compat' - }); - return output; -} diff --git a/build/webpack/lib/transforms/apply-simple-options.js b/build/webpack/lib/transforms/apply-simple-options.js deleted file mode 100644 index 07775568a..000000000 --- a/build/webpack/lib/transforms/apply-simple-options.js +++ /dev/null @@ -1,12 +0,0 @@ - -module.exports = function (options, output) { - output.output = options.output || {filename: '[name]'}; - - if (options.entry) { - output.entry = options.entry; - } - - if (options.loaders) { - output.module.loaders = output.module.loaders.concat(options.loaders); - } -} diff --git a/build/webpack/lib/transforms/babel.js b/build/webpack/lib/transforms/babel.js deleted file mode 100644 index f4f8a85d8..000000000 --- a/build/webpack/lib/transforms/babel.js +++ /dev/null @@ -1,86 +0,0 @@ -const path = require('path'); -const fs = require('fs') -function getBowerLinks () { - try { - return fs.readdirSync(path.join(process.cwd(), './bower_components')).filter(dir => { - const stat = fs.lstatSync('./bower_components/' + dir); - return stat.isSymbolicLink(); - }) - } catch (e) { - return [] - } -} - -module.exports = function (options, output) { - if (!options.language || options.language === 'js') { - const babelConfig = { - test: /\.js$/, - loader: require.resolve('babel-loader'), - include: [ - /bower_components/, - path.resolve('./node_modules/@financial-times/n-handlebars/src/helpers'), - path.resolve('./server/helpers'), // more handlebars helpers - path.resolve('./client'), - path.resolve('./config'), - path.resolve('./shared') - ], - exclude: [], - query: { - babelrc: false, // ignore any .babelrc in project & dependencies - cacheDirectory: true, - plugins: [ - require.resolve('babel-plugin-add-module-exports', true) - ], - presets: [] - } - }; - - // TODO: these modules need to be transpiled - // NOTE: these are npm modules, babel has a freak out if you just include all of /node_modules/ - const es6Modules = [ - '@financial-times/n-card', - '@financial-times/n-email-article', - '@financial-times/n-image', - '@financial-times/n-myft-ui', - '@financial-times/n-notification', - '@financial-times/n-section', - '@financial-times/n-ui', - '@financial-times/n-teaser', - '@financial-times/n-counter-ad-blocking', - '@financial-times/n-native-ads', - '@financial-times/n-tourtip' - ]; - - es6Modules - .concat(options.include || options.includes || []) - .concat(getBowerLinks()) - .forEach(path => babelConfig.include.push(new RegExp(path))); - - (options.exclude || options.excludes || []) - .forEach(path => babelConfig.exclude.push(new RegExp(path))); - - if (options.babelPlugins) { - babelConfig.query.plugins = babelConfig.query.plugins.concat(options.babelPlugins); - } - - if (options.withBabelPolyfills) { - babelConfig.query.plugins.push(require.resolve('babel-plugin-transform-runtime')); - } else { - output.resolve.alias = Object.assign(output.resolve.alias || {}, require('babel-polyfill-silencer/aliases')); - babelConfig.query.plugins.push([require.resolve('babel-plugin-transform-runtime'), {polyfill: false}]); - } - - babelConfig.query.presets.push(require.resolve('babel-preset-react')) - - if (options.ECMAScriptVersion <= 5) { - babelConfig.query.presets.push(require.resolve('babel-preset-es2015')) - babelConfig.query.plugins.push([require.resolve('babel-plugin-transform-es2015-classes'), { loose: true }]) - } else { - babelConfig.query.plugins.push(require.resolve('babel-plugin-transform-es2015-modules-commonjs')); - if (process.argv.indexOf('--dev') === -1) { - babelConfig.compact = true; - } - } - output.module.loaders.unshift(babelConfig); - } -} diff --git a/build/webpack/lib/transforms/base-js.js b/build/webpack/lib/transforms/base-js.js deleted file mode 100644 index fd0168d2d..000000000 --- a/build/webpack/lib/transforms/base-js.js +++ /dev/null @@ -1,44 +0,0 @@ -const BowerWebpackPlugin = require('bower-webpack-plugin'); -const path = require('path'); -const glob = require('glob'); - -const handlebarsConfig = () => { - const extraHelperDirs = glob.sync('**/node_modules/@financial-times/**/handlebars-helpers') - .map(dir => path.resolve(dir)); - return { - debug: false, // set to true to debug finding partial/helper issues - extensions: ['.html'], - helperDirs: [ - path.resolve('./node_modules/@financial-times/n-handlebars/src/helpers'), - path.resolve('./server/helpers'), - path.resolve('./bower_components/n-concept/handlebars-helpers') - ].concat(extraHelperDirs), - partialDirs: [ - path.resolve('./bower_components'), - path.resolve('./node_modules/@financial-times'), - path.resolve('./views/universal') - ] - }; -}; - -module.exports = function (options, output) { - if (!options.language || options.language === 'js') { - output.module.loaders = output.module.loaders.concat([ - // don't use requireText plugin (use the 'raw' plugin) - { - test: /follow-email\.js$/, - loader: require.resolve('imports-loader'), - query: 'requireText=>require' - }, - { - test: /\.html$/, - loader: 'handlebars?' + JSON.stringify(handlebarsConfig()) - } - ]); - output.plugins.push( - new BowerWebpackPlugin({ includes: /\.js$/, modulesDirectories: path.resolve('./bower_components') }) - ) - output.resolveLoader.alias.raw = require.resolve('raw-loader'); - output.resolveLoader.alias.imports = require.resolve('imports-loader'); - } -} diff --git a/build/webpack/lib/transforms/base-scss.js b/build/webpack/lib/transforms/base-scss.js deleted file mode 100644 index 226da444d..000000000 --- a/build/webpack/lib/transforms/base-scss.js +++ /dev/null @@ -1,51 +0,0 @@ -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -const autoprefixer = require('autoprefixer'); -const path = require('path'); - -module.exports = function (options, output) { - if (!options.language || options.language === 'scss') { - const extractOptions = process.argv.indexOf('--dev') === -1 - ? [ 'css?minimize&-autoprefixer&sourceMap', 'postcss', 'sass'] - : [ 'css?sourceMap', 'postcss', 'sass' ] - if (options.cssVariant === 'ie8') { - extractOptions.push('ie8SassOptions') - } - output.module.loaders = output.module.loaders.concat([ - // set 'this' scope to window - { - test: /cssrelpreload\.js$/, - loader: require.resolve('imports-loader'), - query: 'this=>window' - }, - { - test: /\.scss$/, - loader: ExtractTextPlugin.extract(extractOptions) - } - ]); - - output.sassLoader = { - sourcemap: true, - includePaths: [ - path.resolve('./bower_components'), - path.resolve('./node_modules/@financial-times') - ], - // NOTE: This line is important for preservation of comments needed by the css-extract-block plugin - outputStyle: 'expanded' - }; - - output.postcss = () => { - return [ autoprefixer({ - browsers: ['> 1%', 'last 2 versions', 'ie >= 9', 'ff ESR', 'bb >= 7', 'iOS >= 5'], - flexbox: 'no-2009' - }) ]; - }; - - output.resolveLoader.alias.ie8SassOptions = path.join(__dirname, '../addons/ie8-sass-options'); - output.resolveLoader.alias.postcss = require.resolve('postcss-loader'); - output.resolveLoader.alias.sass = require.resolve('sass-loader'); - - output.plugins.push( - new ExtractTextPlugin('[name]') - ) - } -} diff --git a/build/webpack/lib/transforms/base.js b/build/webpack/lib/transforms/base.js deleted file mode 100644 index a0301a42f..000000000 --- a/build/webpack/lib/transforms/base.js +++ /dev/null @@ -1,18 +0,0 @@ -const path =require('path'); -module.exports = function (options, output) { - output.devtool = 'source-map'; - output.resolve = { - root: [ - path.resolve('./bower_components'), - path.resolve('./node_modules') - ] - }; - - output.module = { - loaders: [] - }; - - output.plugins = []; - - output.resolveLoader = {alias: {}}; -} diff --git a/build/webpack/lib/transforms/build-env.js b/build/webpack/lib/transforms/build-env.js deleted file mode 100644 index 047fd32c8..000000000 --- a/build/webpack/lib/transforms/build-env.js +++ /dev/null @@ -1,18 +0,0 @@ -const webpack = require('webpack'); - -module.exports = function (options, output) { - let isProd = false; - if ('env' in options && options.env === 'prod') { - isProd = true; - } - if (!('env' in options) && process.argv.indexOf('--dev') === -1) { - isProd = true; - } - if (isProd) { - output.isProd = true; - output.plugins.push(new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': '"production"' } })); - if (options.ECMAScriptVersion <= 5) { - output.plugins.push(new webpack.optimize.UglifyJsPlugin({ 'compress': { 'warnings': false } })); - } - } -} diff --git a/build/webpack/lib/transforms/stats.js b/build/webpack/lib/transforms/stats.js deleted file mode 100644 index f5cfb6436..000000000 --- a/build/webpack/lib/transforms/stats.js +++ /dev/null @@ -1,10 +0,0 @@ -const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; - -module.exports = function (options, output) { - if (options.outputStats) { - output.plugins.push(new StatsWriterPlugin({ - filename: options.outputStats, - fields: null - })); - } -} diff --git a/build/webpack/webpack.config.js b/build/webpack/webpack.config.js deleted file mode 100644 index edf73ec5d..000000000 --- a/build/webpack/webpack.config.js +++ /dev/null @@ -1,230 +0,0 @@ -/* -This is just porting all the configs from all the seperate transform files and -having one large standard one. This should make it easier to update to webpack 2 -As well as just making it more accessible without having to dive around all the -transforms. Would prefer to have a well commented file like Origami: -*/ - -const path = require('path'); -const glob = require('glob'); -// const BowerWebpackPlugin = require('bower-webpack-plugin'); -const ExtractTextPlugin = require('extract-text-webpack-plugin'); -const autoprefixer = require('autoprefixer'); - - -const handlebarsConfig = () => { - const extraHelperDirs = glob.sync('**/node_modules/@financial-times/**/handlebars-helpers') - .map(dir => path.resolve(dir)); - return { - debug: false, // set to true to debug finding partial/helper issues - extensions: ['.html'], - helperDirs: [ - path.resolve('./node_modules/@financial-times/n-handlebars/src/helpers'), - path.resolve('./server/helpers'), - path.resolve('./bower_components/n-concept/handlebars-helpers') - ].concat(extraHelperDirs), - partialDirs: [ - path.resolve('./bower_components'), - path.resolve('./node_modules/@financial-times'), - path.resolve('./views/universal') - ] - }; -}; - -const extractOptions = [{ - loader: 'css-loader', - options: { - minimize: process.argv.includes('--dev') ? false : true, - sourceMap: true - } - }, - { - loader: 'postcss-loader', - options: { - plugins: () => [ - autoprefixer({ - browsers: ['> 1%', 'last 2 versions', 'ie >= 9', 'ff ESR', 'bb >= 7', 'iOS >= 5'], - flexbox: 'no-2009' - }) - ] - } - }, - { - loader: 'sass-loader', - options: { - sourcemap: true, - includePaths: [ - path.resolve('./bower_components'), - path.resolve('./node_modules/@financial-times') - ], - // NOTE: This line is important for preservation of comments needed by the css-extract-block plugin - outputStyle: 'expanded' - } - } -] - -module.exports = function () { - return { - devtool: 'source-map', - - resolve: { - modules: [ - path.resolve('./bower_components'), - path.resolve('./node_modules'), - // 'bower_components', - // 'node_modules', - ], - // These JSON files are read in directories - descriptionFiles: ['bower.json', 'package.json'], - - // These fields in the description files are looked up when trying to resolve the package directory - mainFields: ['main', 'browser'], - - // These files are tried when trying to resolve a directory - mainFiles: [ - 'index', - 'main', - 'src/main-client' /* HACK: this is becaause of n-image's entrypoin not being main.js or index.js */ - ], - - // These fields in the description files offer aliasing in this package - // The content of these fields is an object where requests to a key are mapped to the corresponding value - aliasFields: ['browser'], - - // These extensions are tried when resolving a file - extensions: ['.js', '.json'], - - alias: Object.assign(require('babel-polyfill-silencer/aliases'), { - 'react': 'preact-compat', - 'react-dom': 'preact-compat' - }), - }, - - module: { - rules: [ - //babel - { - test: /\.js$/, - loader: require.resolve('babel-loader'), - include: [ - /bower_components/, - path.resolve('./node_modules/@financial-times/n-handlebars/src/helpers'), - path.resolve('./server/helpers'), // more handlebars helpers - path.resolve('./client'), - path.resolve('./config'), - path.resolve('./shared'), - /@financial-times\/n-card/, - /@financial-times\/n-email-article/, - /@financial-times\/n-image/, - /@financial-times\/n-myft-ui/, - /@financial-times\/n-notification/, - /@financial-times\/n-section/, - /@financial-times\/n-ui/, - /@financial-times\/n-teaser/, - /@financial-times\/n-counter-ad-blocking/, - /@financial-times\/n-native-ads/, - /@financial-times\/n-tourtip/, - /.*/ - ], - exclude: [ - /node_modules/ - ], - query: { - babelrc: false, // ignore any .babelrc in project & dependencies - cacheDirectory: true, - plugins: [ - require.resolve('babel-plugin-add-module-exports', true), - [ - require.resolve('babel-plugin-transform-runtime'), - { - polyfill: false - } - ], - // require.resolve('babel-plugin-transform-es2015-modules-commonjs'), // not sure this was ever actually used?? - [ - require.resolve('babel-plugin-transform-es2015-classes'), - { - loose: true - } - ] - ], - presets: [ - require.resolve('babel-preset-react'), - require.resolve('babel-preset-es2015') - ] - }, - // compact: process.argv.includes('--dev') ? false : true // not sure this was ever actually used?? - - }, - //base-js - // don't use requireText plugin (use the 'raw' plugin) - { - test: /follow-email\.js$/, - loader: require.resolve('imports-loader'), - query: 'requireText=>require' - }, - { - test: /\.html$/, - loader: 'handlebars', - options: handlebarsConfig() - }, - // base-scss - // set 'this' scope to window - { - test: /cssrelpreload\.js$/, - loader: require.resolve('imports-loader'), - query: 'this=>window' - }, - { - test: /\.scss$/, - loader: ExtractTextPlugin.extract({ - use: extractOptions - }) - } - ] - }, - - // sassLoader: { - // sourcemap: true, - // includePaths: [ - // path.resolve('./bower_components'), - // path.resolve('./node_modules/@financial-times') - // ], - // // NOTE: This line is important for preservation of comments needed by the css-extract-block plugin - // outputStyle: 'expanded' - // }, - // - // postcss: () => { - // return [ autoprefixer({ - // browsers: ['> 1%', 'last 2 versions', 'ie >= 9', 'ff ESR', 'bb >= 7', 'iOS >= 5'], - // flexbox: 'no-2009' - // }) ]; - // }, - - plugins: [ - // new BowerWebpackPlugin({ - // includes: /\.js$/, - // modulesDirectories: path.resolve('./bower_components') - // }), - new ExtractTextPlugin('[name]'), - - - ], - - resolveLoader: { - alias: { - raw: 'raw-loader', - imports: 'imports-loader', - postcss: 'postcss-loader', - sass: 'sass-loader', - } - }, - - output: { - filename: '[name]', - library: 'ftNextUi', // assigns to window.ftNextUi - devtoolModuleFilenameTemplate: 'n-ui//[resource-path]?[loaders]' - } - }; - -}