build: move styled-jsx to dependencies

This commit is contained in:
unix
2020-04-17 17:16:26 +08:00
parent b4c6a17a9f
commit de3f33f6f6
2 changed files with 42 additions and 27 deletions

View File

@@ -2,65 +2,79 @@ const fs = require('fs-extra')
const path = require('path')
const componentsPath = path.join(__dirname, '../components')
module.exports = async () => {
module.exports = async() => {
const files = await fs.readdir(componentsPath)
const components = await Promise.all(files.map(async name => {
const comPath = path.join(componentsPath, name)
const entry = path.join(comPath, 'index.ts')
const stat = await fs.stat(comPath)
if (!stat.isDirectory()) return null
const hasFile = await fs.pathExists(entry)
if (!hasFile) return null
return { name, url: entry }
}))
const componentsEntries = components
.filter(r => r)
.reduce((pre, current) => {
return Object.assign({}, pre, { [current.name]: current.url })
}, { index: path.join(componentsPath, 'index.ts') })
return Object.assign({}, pre, { [current.name]: current.url })
}, { index: path.join(componentsPath, 'index.ts') })
console.log(`\n${Object.keys(componentsEntries).length} Components in total have been collected.`)
console.log('Bundle now...')
return {
mode: 'production',
entry: componentsEntries,
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../dist'),
library: '',
libraryTarget: 'commonjs',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
components: componentsPath,
},
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
externals: [
{
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
// '/styled-jsx/': {
// root: '_JSXStyle',
// commonjs2: 'styled-jsx',
// commonjs: 'styled-jsx',
// amd: 'styled-jsx',
// },
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
}
},
function(context, request, done) {
if (/^styled-jsx/.test(request)){
return done(null, 'commonjs ' + request)
}
done()
},
],
module: {
rules: [
{