Skip to content

Commit

Permalink
Adjust eject script
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Apr 16, 2017
1 parent b7ed2fd commit c96ec91
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 69 deletions.
87 changes: 40 additions & 47 deletions packages/cycle-scripts/configs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'
module.exports = language => `'use strict'
// Silence webpack2 deprecation warnings
// https://github.com/vuejs/vue-loader/issues/666
Expand All @@ -15,18 +15,15 @@ const addPlugins = webpack2Block.addPlugins
const babel = require('@webpack-blocks/babel6');
const devServer = require('@webpack-blocks/dev-server2');
const typescript = require('@webpack-blocks/typescript');
const webpack = require('webpack');
${language === 'javascript' ? '' : `const typescript = require('@webpack-blocks/typescript');
`}const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require('path');
const babelConfig = {
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
// We speficy here which presets to use. In the future this could be moved to it's own
// package as create-react-app does with their 'babel-preset-react-app module.
Expand All @@ -49,48 +46,44 @@ const babelConfig = {
]
}
module.exports = function(language) {
const ending = language === 'javascript' ? '.js' : '.ts'
const baseConfig = [
entryPoint(path.join(process.cwd(), 'src', 'index' + ending)),
setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
babel(babelConfig),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV
const config = [
entryPoint(path.join(process.cwd(), 'src', 'index.${language === 'javascript' ? 'js' : 'ts' }')),
setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
babel(Object.assign({}, babelConfig, { cacheDirectory: true })),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV
}),
addPlugins([
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true,
favicon: 'public/favicon.png',
hash: true
}),
new webpack.ProvidePlugin({
Snabbdom: 'snabbdom-pragma'
})
]),
env('development', [
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
sourceMaps() //The default is cheap-module-source-map
]),
env('production', [
addPlugins([
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true,
favicon: 'public/favicon.png',
hash: true
}),
new webpack.ProvidePlugin({
Snabbdom: 'snabbdom-pragma'
})
]),
env('development', [
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
sourceMaps() //The default is cheap-module-source-map
]),
env('production', [
addPlugins([
new webpack.optimize.UglifyJsPlugin(),
new CopyWebpackPlugin([{ from: 'public', to: '' }])
])
])
]

const config = language === 'javascript' ? baseConfig : baseConfig
.concat([
typescript({
tsconfig: path.join(__dirname, 'tsconfig.json'),
useBabel: true,
babelOptions: babelConfig,
useCache: true,
cacheDirectory: 'node_modules/.cache/at-loader'
new webpack.optimize.UglifyJsPlugin(),
new CopyWebpackPlugin([{ from: 'public', to: '' }]),
new CleanWebpackPlugin([ path.join(process.cwd(), 'build') ], {
root: process.cwd()
})
])
])${language === 'javascript' ? '' : `,
typescript({
configFileName: path.join(__dirname, '..', 'configs', 'tsconfig.json'),
useBabel: true,
babelOptions: babelConfig,
useCache: true,
cacheDirectory: 'node_modules/.cache/at-loader'
})` }
]
return createConfig(config)
}
module.exports = createConfig(config)`
Empty file modified packages/cycle-scripts/index.js
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions packages/cycle-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.3.3",
"chalk": "^1.1.3",
"clean-webpack-plugin": "^0.1.16",
"copy-webpack-plugin": "^4.0.1",
"cross-spawn": "^5.1.0",
"fs-extra": "^2.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cycle-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const FileSizeReporter = require('react-dev-utils/FileSizeReporter')
const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild

const config = require('../configs/webpack.config')(notEjected.language)
const config = eval(require('../configs/webpack.config')(notEjected.language))

measureFileSizesBeforeBuild(buildPath).then(previousFileSizes => {
// Start the webpack build
Expand Down
38 changes: 18 additions & 20 deletions packages/cycle-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@ inquirer.prompt([ejectConfirmation]).then(answers => {
// STEP 1 - Prepare package.json
// Declaring new scripts
const scripts = {
start: 'node scripts/start.js',
test: 'node scripts/test.js',
build: 'node scripts/build.js'
start: 'NODE_ENV=development webpack-dev-server --config webpack.config.js',
build: 'NODE_ENV=production webpack --config webpack.config.js'
}

const language = appPackageJson.cca.language

// Remove flavor from devpendencies
delete appPackageJson.devDependencies[flavorPackageJson.name]
// Remove cca settings
delete appPackageJson.cca
// Flavor's dependencies -> application devDependency.
// We merge flavor's dependencies with application's devDepependencies
const devDependencies = Object.assign(
let devDependencies = Object.assign(
{},
appPackageJson.devDependencies,
flavorPackageJson.dependencies
)
const preEjectDependencies = ['inquirer', 'cross-spawn', 'fs-extra', 'chalk']
preEjectDependencies.forEach(dep => {
delete devDependencies[dep]
})

// New package.json content
const packageJsonContent = Object.assign(
{},
Expand All @@ -59,23 +66,14 @@ inquirer.prompt([ejectConfirmation]).then(answers => {
JSON.stringify(packageJsonContent, null, 2)
)

// STEP 2 - Copy scripts
function copyScript (script) {
fs.copySync(path.join(__dirname, script), path.join(appScriptsPath, script))
}
// Make sure appScriptsPath exists
fs.ensureDirSync(appScriptsPath)
// Copy over start, test and build scripts
copyScript('start.js')
copyScript('test.js')
copyScript('build.js')

// STEP 3 - Copy utils
fs.copySync(path.join(__dirname, 'utils'), path.join(appScriptsPath, 'utils'))
// STEP 2 - Copy configs
const configPath = path.join(__dirname, '..', 'configs')
const wpconfig = require('../configs/webpack.config')(language)
fs.writeFileSync(path.join(appPath, 'webpack.config.js'), wpconfig)

// STEP 4 - Copy configs
fs.copySync(path.join(__dirname, '../', 'configs', language), path.join(appPath, 'configs'))
fs.copySync(path.join(__dirname, '../', 'configs', 'webpackDevServer.config.js'), path.join(appPath, 'configs', 'webpackDevServer.config.js'))
if(language === 'typescript') {
fs.copySync(path.join(configPath, 'tsconfig.json'), appPath)
}

// TODO sucess message
})
2 changes: 1 addition & 1 deletion packages/cycle-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const createWebpackCompiler = require('./utils/createWebpackCompiler')
const openBrowser = require('react-dev-utils/openBrowser')
const notEjected = require(path.join(process.cwd(), 'package.json')).cca

const config = require('../configs/webpack.config')(notEjected.language)
const config = eval(require('../configs/webpack.config')(notEjected.language))

const cli = 'npm'
const protocol = 'http'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = replacements => `${replacements.import}
${replacements.typeImport}
import {DOMSource, VNode} from '@cycle/dom'
export type Sources = {
Expand Down

0 comments on commit c96ec91

Please sign in to comment.