mirror of
https://github.com/zhigang1992/docz.git
synced 2026-03-27 02:34:14 +08:00
chore(docz-bundler-webpack): some refacs
This commit is contained in:
@@ -3,70 +3,64 @@ import { Configuration } from 'webpack'
|
||||
import * as webpack from 'webpack'
|
||||
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
|
||||
import * as WebpackDevServer from 'webpack-dev-server'
|
||||
import { ConfigArgs as Config, Entry } from 'docz-core'
|
||||
import { ConfigArgs as Config } from 'docz-core'
|
||||
import webpackDevServerUtils from 'react-dev-utils/WebpackDevServerUtils'
|
||||
|
||||
import { devServerConfig } from './config-devserver'
|
||||
import * as loaders from './loaders'
|
||||
|
||||
export const config = ({ paths, host, src }: Config) => (
|
||||
entries: Entry[]
|
||||
): Configuration => {
|
||||
const srcPath = path.resolve(paths.root, src)
|
||||
|
||||
return {
|
||||
mode: 'development',
|
||||
devtool: '#source-map',
|
||||
context: paths.root,
|
||||
entry: [
|
||||
require.resolve('babel-polyfill'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
paths.indexJs,
|
||||
],
|
||||
output: {
|
||||
pathinfo: true,
|
||||
path: paths.dist,
|
||||
publicPath: '/',
|
||||
filename: 'static/js/[name].js',
|
||||
sourceMapFilename: 'static/js/[name].js.map',
|
||||
crossOriginLoading: 'anonymous',
|
||||
devtoolModuleFilenameTemplate: (info: any) =>
|
||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
exclude: /node_modules/,
|
||||
include: [srcPath, paths.docz],
|
||||
use: [require.resolve('thread-loader'), loaders.babel],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
modules: ['node_modules', srcPath],
|
||||
alias: {
|
||||
'@babel/runtime': path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
),
|
||||
export const config = ({ paths, host }: Config) => (): Configuration => ({
|
||||
mode: 'development',
|
||||
devtool: '#source-map',
|
||||
context: paths.root,
|
||||
entry: [
|
||||
require.resolve('babel-polyfill'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
paths.indexJs,
|
||||
],
|
||||
output: {
|
||||
pathinfo: true,
|
||||
path: paths.dist,
|
||||
publicPath: '/',
|
||||
filename: 'static/js/[name].js',
|
||||
sourceMapFilename: 'static/js/[name].js.map',
|
||||
crossOriginLoading: 'anonymous',
|
||||
devtoolModuleFilenameTemplate: (info: any) =>
|
||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
exclude: /node_modules/,
|
||||
include: [paths.root, paths.docz],
|
||||
use: [require.resolve('thread-loader'), loaders.babel],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.indexHtml,
|
||||
}),
|
||||
],
|
||||
}
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
modules: ['node_modules', paths.root],
|
||||
alias: {
|
||||
'@babel/runtime': path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.indexHtml,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
export const compiler = ({ paths, port, host, protocol }: Config) => (
|
||||
config: Configuration
|
||||
|
||||
Reference in New Issue
Block a user