Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 39296f0

Browse files
Adjust eject script
1 parent b7ed2fd commit 39296f0

File tree

6 files changed

+51
-58
lines changed

6 files changed

+51
-58
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
1+
module.exports = (language, ejected = false) => `'use strict'
32
// Silence webpack2 deprecation warnings
43
// https://github.com/vuejs/vue-loader/issues/666
54
process.noDeprecation = true
6-
75
const webpack2Block = require('@webpack-blocks/webpack2');
86
const createConfig = webpack2Block.createConfig
97
const defineConstants = webpack2Block.defineConstants
@@ -12,21 +10,15 @@ const entryPoint = webpack2Block.entryPoint
1210
const setOutput = webpack2Block.setOutput
1311
const sourceMaps = webpack2Block.sourceMaps
1412
const addPlugins = webpack2Block.addPlugins
15-
1613
const babel = require('@webpack-blocks/babel6');
1714
const devServer = require('@webpack-blocks/dev-server2');
18-
const typescript = require('@webpack-blocks/typescript');
19-
const webpack = require('webpack');
15+
${language==='javascript' ? '' : `const typescript = require('@webpack-blocks/typescript');
16+
`}const webpack = require('webpack');
2017
const HtmlWebpackPlugin = require('html-webpack-plugin');
2118
const CopyWebpackPlugin = require('copy-webpack-plugin');
22-
19+
const CleanWebpackPlugin = require('clean-webpack-plugin');
2320
const path = require('path');
24-
2521
const babelConfig = {
26-
// This is a feature of `babel-loader` for webpack (not Babel itself).
27-
// It enables caching results in ./node_modules/.cache/babel-loader/
28-
// directory for faster rebuilds.
29-
cacheDirectory: true,
3022
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
3123
// We speficy here which presets to use. In the future this could be moved to it's own
3224
// package as create-react-app does with their 'babel-preset-react-app module.
@@ -48,49 +40,44 @@ const babelConfig = {
4840
['transform-object-rest-spread']
4941
]
5042
}
51-
52-
module.exports = function(language) {
53-
const ending = language === 'javascript' ? '.js' : '.ts'
54-
const baseConfig = [
55-
entryPoint(path.join(process.cwd(), 'src', 'index' + ending)),
56-
setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
57-
babel(babelConfig),
58-
defineConstants({
59-
'process.env.NODE_ENV': process.env.NODE_ENV
43+
const config = [
44+
entryPoint(path.join(process.cwd(), 'src', 'index.${language === 'javascript' ? 'js' : 'ts' }')),
45+
setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
46+
babel(Object.assign({}, babelConfig, { cacheDirectory: true })),
47+
defineConstants({
48+
'process.env.NODE_ENV': process.env.NODE_ENV
49+
}),
50+
addPlugins([
51+
new HtmlWebpackPlugin({
52+
template: 'public/index.html',
53+
inject: true,
54+
favicon: 'public/favicon.png',
55+
hash: true
6056
}),
57+
new webpack.ProvidePlugin({
58+
Snabbdom: 'snabbdom-pragma'
59+
})
60+
]),
61+
env('development', [
62+
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
63+
sourceMaps() //The default is cheap-module-source-map
64+
]),
65+
env('production', [
6166
addPlugins([
62-
new HtmlWebpackPlugin({
63-
template: 'public/index.html',
64-
inject: true,
65-
favicon: 'public/favicon.png',
66-
hash: true
67-
}),
68-
new webpack.ProvidePlugin({
69-
Snabbdom: 'snabbdom-pragma'
70-
})
71-
]),
72-
env('development', [
73-
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
74-
sourceMaps() //The default is cheap-module-source-map
75-
]),
76-
env('production', [
77-
addPlugins([
78-
new webpack.optimize.UglifyJsPlugin(),
79-
new CopyWebpackPlugin([{ from: 'public', to: '' }])
80-
])
81-
])
82-
]
83-
84-
const config = language === 'javascript' ? baseConfig : baseConfig
85-
.concat([
86-
typescript({
87-
tsconfig: path.join(__dirname, 'tsconfig.json'),
88-
useBabel: true,
89-
babelOptions: babelConfig,
90-
useCache: true,
91-
cacheDirectory: 'node_modules/.cache/at-loader'
67+
new webpack.optimize.UglifyJsPlugin(),
68+
new CopyWebpackPlugin([{ from: 'public', to: '' }]),
69+
new CleanWebpackPlugin([ path.join(process.cwd(), 'build') ], {
70+
root: process.cwd()
9271
})
9372
])
94-
95-
return createConfig(config)
96-
}
73+
])${language === 'javascript' ? '' : `,
74+
typescript({${ !ejected ? `
75+
configFileName:path.join(__dirname, '..', 'configs', 'tsconfig.json'),` : '' }
76+
useBabel: true,
77+
babelOptions: babelConfig,
78+
useCache: true,
79+
cacheDirectory: 'node_modules/.cache/at-loader'
80+
})` }
81+
]
82+
module.exports = createConfig(config)
83+
`

‎packages/cycle-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"babel-plugin-transform-react-jsx": "^6.24.1",
3939
"babel-preset-env": "^1.3.3",
4040
"chalk": "^1.1.3",
41+
"clean-webpack-plugin": "^0.1.16",
4142
"copy-webpack-plugin": "^4.0.1",
4243
"cross-spawn": "^5.1.0",
4344
"fs-extra": "^2.1.2",

‎packages/cycle-scripts/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const FileSizeReporter = require('react-dev-utils/FileSizeReporter')
4747
const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild
4848
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild
4949

50-
const config = require('../configs/webpack.config')(notEjected.language)
50+
const config = notEjected ? eval(require('../configs/webpack.config.template')(notEjected.language)) : require(path.join(process.cwd(),'webpack.config.js'))
5151

5252
measureFileSizesBeforeBuild(buildPath).then(previousFileSizes => {
5353
// Start the webpack build

‎packages/cycle-scripts/scripts/eject.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ inquirer.prompt([ejectConfirmation]).then(answers => {
3333
test: 'node scripts/test.js',
3434
build: 'node scripts/build.js'
3535
}
36+
const language = appPackageJson.cca.language
3637
// Remove flavor from devpendencies
3738
delete appPackageJson.devDependencies[flavorPackageJson.name]
3839
// Remove cca settings
@@ -74,8 +75,11 @@ inquirer.prompt([ejectConfirmation]).then(answers => {
7475
fs.copySync(path.join(__dirname, 'utils'), path.join(appScriptsPath, 'utils'))
7576

7677
// STEP 4 - Copy configs
77-
fs.copySync(path.join(__dirname, '../', 'configs', language), path.join(appPath, 'configs'))
78-
fs.copySync(path.join(__dirname, '../', 'configs', 'webpackDevServer.config.js'), path.join(appPath, 'configs', 'webpackDevServer.config.js'))
78+
const configString = require(path.join(__dirname, '..', 'configs', 'webpack.config.template.js'))(language)
79+
fs.writeFileSync(path.join(appPath, 'webpack.config.js'), configString)
80+
if(language === 'typescript') {
81+
fs.copySync(path.join(__dirname, '../', 'configs', 'tsconfig.json'), path.join(appPath, 'tsconfig.json'))
82+
}
7983

8084
// TODO sucess message
8185
})

‎packages/cycle-scripts/scripts/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const createWebpackCompiler = require('./utils/createWebpackCompiler')
4242
const openBrowser = require('react-dev-utils/openBrowser')
4343
const notEjected = require(path.join(process.cwd(), 'package.json')).cca
4444

45-
const config = require('../configs/webpack.config')(notEjected.language)
45+
const config = notEjected ? eval(require('../configs/webpack.config.template')(notEjected.language)) : require(path.join(process.cwd(),'webpack.config.js'))
4646

4747
const cli = 'npm'
4848
const protocol = 'http'

‎packages/cycle-scripts/template/src/typescript/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = replacements => `${replacements.import}
2+
${replacements.typeImport}
23
import {DOMSource, VNode} from '@cycle/dom'
34
45
export type Sources = {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /