Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use webpack for extensions instead of parcel #202

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 63 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ const testsEnabled = true
const devDependencies: string[] = [
'sourcegraph',
'typescript',
'parcel-bundler',
'eslint',
'@sourcegraph/eslint-config',
'@sourcegraph/tsconfig',
'lnfs-cli',
'mkdirp',
// Pin versions for webpack dependencies to prevent incompatibility with our `webpack.config.js`.
// Periodically test and upgrade them as a unit.
'webpack@5.51.1',
'webpack-cli@4.8.0',
'webpack-dev-server@3.11.2',
'ts-loader@9.2.5',
'copy-webpack-plugin@9.0.1',
]

/**
Expand Down Expand Up @@ -166,6 +170,7 @@ async function main(): Promise<void> {
parserOptions: {
project: 'tsconfig.json',
},
ignorePatterns: ['webpack.config.js'],
}
await writeFile('.eslintrc.json', JSON.stringify(eslintJson, null, 2))
}
Expand Down Expand Up @@ -201,6 +206,59 @@ async function main(): Promise<void> {
console.log('📄 Adding .gitignore')
await writeFile('.gitignore', ['dist/', 'node_modules/', '.cache/', ''].join('\n'))

if (await exists('webpack.config.js')) {
console.log('📄 webpack.config.js already exists, skipping creation')
} else {
console.log('📄 Adding webpack.config.js')
await writeFile(
'webpack.config.js',
[
"const path = require('path')",
"const CopyPlugin = require('copy-webpack-plugin')",
'',
'module.exports = {',
` entry: './src/${name}.ts',`,
' module: {',
' rules: [',
' {',
' test: /.ts?$/,',
" use: 'ts-loader',",
' exclude: /node_modules/,',
' },',
' ],',
' },',
' resolve: {',
" extensions: ['.ts', '.js'],",
' },',
' output: {',
" path: path.resolve(__dirname, 'dist'),",
` filename: '${name}.js',`,
' library: {',
" type: 'umd',",
' },',
" globalObject: 'self',",
' },',
' devServer: {',
" contentBase: path.join(__dirname, 'dist'),",
' compress: true,',
' port: 1234,',
' inline: false,',
' headers: {',
" 'Access-Control-Allow-Origin': '*',",
' },',
' writeToDisk: true,',
' },',
' plugins: [',
' new CopyPlugin({',
" patterns: [{ from: './package.json', to: 'package.json' }],",
' }),',
' ],',
'}',
'',
].join('\n')
)
}

if (await exists('package.json')) {
console.log('📄 package.json already exists, skipping creation')
} else {
Expand Down Expand Up @@ -229,9 +287,8 @@ async function main(): Promise<void> {
scripts: {
eslint: "eslint 'src/**/*.ts'",
typecheck: 'tsc -p tsconfig.json',
build: `parcel build --out-file dist/${name}.js src/${name}.ts`,
'symlink-package': 'mkdirp dist && lnfs ./package.json ./dist/package.json',
serve: `yarn run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
build: 'webpack --config webpack.config.js',
serve: 'npx webpack serve',
'watch:typecheck': 'tsc -p tsconfig.json -w',
'watch:build': 'tsc -p tsconfig.dist.json -w',
'sourcegraph:prepublish': 'yarn run typecheck && yarn run build',
Expand Down