Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 028cfcd

Browse files
authored
chore: reorganize configuration (#242)
1 parent ac07c1b commit 028cfcd

File tree

18 files changed

+156
-175
lines changed

18 files changed

+156
-175
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
npm-debug.log
3+
yarn-error.log
34
.DS_Store
45

56
# Ignore build/ except for the Phabricator package.json

config/shared/webpack.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import sassImportOnce from 'node-sass-import-once'
2+
import * as path from 'path'
3+
import * as webpack from 'webpack'
4+
5+
export const buildStylesLoaders = (baseLoader: webpack.Loader): webpack.Loader[] => [
6+
baseLoader,
7+
{ loader: 'postcss-loader' },
8+
{
9+
loader: 'sass-loader',
10+
options: {
11+
includePaths: [path.resolve(__dirname, '../..', 'node_modules')],
12+
importer: sassImportOnce,
13+
importOnce: {
14+
css: true,
15+
},
16+
},
17+
},
18+
]
19+
20+
const babelLoader: webpack.RuleSetUseItem = {
21+
loader: 'babel-loader',
22+
options: {
23+
cacheDirectory: true,
24+
},
25+
}
26+
27+
export const tsRule: webpack.RuleSetRule = {
28+
test: /\.tsx?$/,
29+
use: [
30+
babelLoader,
31+
{
32+
loader: 'ts-loader',
33+
options: {
34+
compilerOptions: {
35+
target: 'es6',
36+
module: 'esnext',
37+
noEmit: false, // tsconfig.json sets this to true to avoid output when running tsc manually
38+
},
39+
transpileOnly: process.env.DISABLE_TYPECHECKING === 'true',
40+
},
41+
},
42+
],
43+
}
44+
45+
export const jsRule: webpack.RuleSetRule = {
46+
test: /\.jsx?$/,
47+
loader: babelLoader,
48+
}
File renamed without changes.

config/storybook/config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { configure } from '@storybook/react'
2+
3+
// automatically import all files ending in *.stories.js
4+
const req = require.context('../../stories', true, /\.tsx?$/)
5+
function loadStories(): void {
6+
for (const filename of req.keys()) {
7+
req(filename)
8+
}
9+
}
10+
11+
configure(loadStories, module)
File renamed without changes.

storybook/tsconfig.json renamed to config/storybook/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../tsconfig.json",
2+
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"rootDirs": ["src", "stories"]
55
}

config/storybook/webpack.config.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as webpack from 'webpack'
2+
import { buildStylesLoaders, jsRule, tsRule } from '../shared/webpack'
3+
4+
const buildWebpackConfig = (
5+
baseConfig: webpack.Configuration,
6+
env: any,
7+
config: webpack.Configuration
8+
): webpack.Configuration => {
9+
config.module!.rules.push(tsRule)
10+
config.module!.rules.push(jsRule)
11+
config.resolve!.extensions!.push('.ts', '.tsx')
12+
13+
// Put our style rules at the beginning so they're processed by the time it
14+
// gets to storybook's style rules.
15+
config.module!.rules.unshift({
16+
test: /\.(css|sass|scss)$/,
17+
use: buildStylesLoaders('style-loader'),
18+
})
19+
20+
return config
21+
}
22+
23+
export default buildWebpackConfig

config/webpack/base.config.ts

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import ExtractTextPlugin from 'extract-text-webpack-plugin'
2+
import * as path from 'path'
3+
import * as webpack from 'webpack'
4+
5+
import { buildStylesLoaders, jsRule, tsRule } from '../shared/webpack'
6+
7+
const buildEntry = (...files) => files.map(file => path.join(__dirname, file))
8+
9+
const contentEntry = '../../src/config/content.entry.js'
10+
const backgroundEntry = '../../src/config/background.entry.js'
11+
const linkEntry = '../../src/config/link.entry.js'
12+
const optionsEntry = '../../src/config/options.entry.js'
13+
const pageEntry = '../../src/config/page.entry.js'
14+
const extEntry = '../../src/config/extension.entry.js'
15+
16+
export default {
17+
entry: {
18+
background: buildEntry(extEntry, backgroundEntry, '../../src/extension/scripts/background.tsx'),
19+
link: buildEntry(extEntry, linkEntry, '../../src/extension/scripts/link.tsx'),
20+
options: buildEntry(extEntry, optionsEntry, '../../src/extension/scripts/options.tsx'),
21+
inject: buildEntry(extEntry, contentEntry, '../../src/extension/scripts/inject.tsx'),
22+
phabricator: buildEntry(pageEntry, '../../src/libs/phabricator/extension.tsx'),
23+
24+
bootstrap: path.join(__dirname, '../../node_modules/bootstrap/dist/css/bootstrap.css'),
25+
style: path.join(__dirname, '../../src/shared/app.scss'),
26+
},
27+
output: {
28+
path: path.join(__dirname, '../../build/dist/js'),
29+
filename: '[name].bundle.js',
30+
chunkFilename: '[id].chunk.js',
31+
},
32+
plugins: [
33+
new ExtractTextPlugin({
34+
filename: '../css/[name].bundle.css',
35+
allChunks: true,
36+
}),
37+
],
38+
resolve: {
39+
extensions: ['.ts', '.tsx', '.js'],
40+
},
41+
module: {
42+
rules: [
43+
tsRule,
44+
jsRule,
45+
{
46+
// SCSS rule for our own styles and Bootstrap
47+
test: /\.(css|sass|scss)$/,
48+
use: ExtractTextPlugin.extract(
49+
buildStylesLoaders({
50+
loader: 'css-loader',
51+
options: {
52+
minimize: process.env.NODE_ENV === 'production',
53+
},
54+
})
55+
),
56+
},
57+
],
58+
},
59+
} as webpack.Configuration

webpack/dev.config.ts renamed to config/webpack/dev.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const entries = entry as webpack.Entry
99

1010
const entriesWithAutoReload = {
1111
...entries,
12-
background: [path.join(__dirname, '../src/extension/scripts/auto-reloading.ts'), ...entries.background],
12+
background: [path.join(__dirname, '../../src/extension/scripts/auto-reloading.ts'), ...entries.background],
1313
}
1414

1515
export default {
File renamed without changes.

webpack/utils.ts renamed to config/webpack/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import extensionInfo from '../src/extension/manifest.spec.json'
1+
import extensionInfo from '../../src/extension/manifest.spec.json'
22

33
/**
44
* Generates a unique bundle ID that is used to prevent the Phabricator extension

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"cypress:open": "yarn run build && cypress open",
1717
"test:e2e": "yarn run build && cypress run --browser chrome",
1818
"prettier": "prettier '**/{*.{js?(on),ts?(x),graphql,md,scss},.*.js?(on)}' --write --list-different --config prettier.config.js",
19-
"storybook": "start-storybook -c ./storybook -p 6006",
20-
"build-storybook": "build-storybook -c ./storybook"
19+
"storybook": "start-storybook -c ./config/storybook -p 6006",
20+
"build-storybook": "build-storybook -c ./config/storybook"
2121
},
2222
"husky": {
2323
"hooks": {

scripts/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import signale from 'signale'
22
import webpack from 'webpack'
3-
import config from '../webpack/prod.config'
3+
import config from '../config/webpack/prod.config'
44
import * as tasks from './tasks'
55

66
const buildChrome = tasks.buildChrome('prod')

scripts/dev.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { noop } from 'lodash'
22
import signale from 'signale'
33
import webpack from 'webpack'
4-
import config from '../webpack/dev.config'
4+
import config from '../config/webpack/dev.config'
55
import * as autoReloading from './auto-reloading'
66
import * as tasks from './tasks'
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'node-sass-import-once' {
2+
import { Plugin } from 'webpack'
3+
class NodeSassImportOncePlugin extends Plugin {
4+
constructor(options: any)
5+
}
6+
export = NodeSassImportOncePlugin
7+
}

storybook/config.js

-9
This file was deleted.

storybook/webpack.config.js

-64
This file was deleted.

webpack/base.config.ts

-95
This file was deleted.

0 commit comments

Comments
 (0)