Skip to content

Commit

Permalink
config nextjs config
Browse files Browse the repository at this point in the history
  • Loading branch information
limichange committed Jan 5, 2020
1 parent aa218f9 commit fa04cac
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@zeit/next-typescript": "^1.1.1",
"antd": "^3.20.2",
"classnames": "^2.2.6",
"css-loader": "^3.0.0",
"css-loader": "^3.4.1",
"dayjs": "^1.8.15",
"electron-better-ipc": "^0.3.0",
"electron-context-menu": "^0.12.1",
Expand Down
43 changes: 43 additions & 0 deletions renderer/config/withCSS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const cssLoaderConfig = require('@zeit/next-css/css-loader-config')

module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}

const { dev, isServer } = options
const { cssModules, cssLoaderOptions, postcssLoaderOptions } = nextConfig

options.defaultLoaders.css = cssLoaderConfig(config, {
extensions: ['css'],
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer
})

config.module.rules.push({
test: /\.css$/,
use: Object.assign(options.defaultLoaders.css, { cssModules: true }),
exclude: /node_modules/
})

config.module.rules.push({
test: /\.css$/,
use: Object.assign(options.defaultLoaders.css, { cssModules: false }),
include: /node_modules/
})

if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}

return config
}
})
}
85 changes: 85 additions & 0 deletions renderer/config/withLess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const cssLoaderConfig = require('@zeit/next-css/css-loader-config')

module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}

const { dev, isServer } = options
const {
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
lessLoaderOptions = {}
} = nextConfig

options.defaultLoaders.less = cssLoaderConfig(config, {
extensions: ['less'],
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions
}
]
})

// config.module.rules.push({
// test: /\.less$/,
// use: options.defaultLoaders.less
// })

config.module.rules.push({
test: /\.less$/,
use: cssLoaderConfig(config, {
extensions: ['less'],
cssModules: true,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions
}
]
}),
exclude: /node_modules/
})

config.module.rules.push({
test: /\.less$/,
use: cssLoaderConfig(config, {
extensions: ['less'],
cssModules: false,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions
}
]
}),
include: /node_modules/
})

if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}

return config
}
})
}
1 change: 1 addition & 0 deletions renderer/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/// <reference types="next/types/global" />

declare module '*.png'
declare module '*.less'
79 changes: 39 additions & 40 deletions renderer/next.config.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
const withLess = require('@zeit/next-less')
const withLess = require('./config/withLess')
const withCss = require('./config/withCSS')
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')

module.exports = withLess({
lessLoaderOptions: {
javascriptEnabled: true
},
webpack(config) {
config.module.rules = [
...config.module.rules,
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.ttf$/,
use: ['file-loader?outputPath=static']
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: ['url-loader']
}
]
module.exports = withCss(
withLess({
lessLoaderOptions: {
javascriptEnabled: true
},
webpack(config) {
config.module.rules = [
...config.module.rules,
{
test: /\.ttf$/,
use: ['file-loader?outputPath=static']
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: ['url-loader']
}
]

config.plugins.push(
new MonacoWebpackPlugin({
publicPath: '_next',
filename: `static/[name].worker.js`
})
)
config.plugins.push(
new MonacoWebpackPlugin({
publicPath: '_next',
filename: `static/[name].worker.js`
})
)

return Object.assign(config, {
target: 'electron-renderer',
devtool: 'cheap-module-source-map',
plugins: config.plugins.filter(p => {
return p.constructor.name !== 'UglifyJsPlugin'
return Object.assign(config, {
target: 'electron-renderer',
devtool: 'cheap-module-source-map',
plugins: config.plugins.filter(p => {
return p.constructor.name !== 'UglifyJsPlugin'
})
})
})
},
useFileSystemPublicRoutes: false,
exportPathMap() {
return {
'/main': { page: '/main' }
},
useFileSystemPublicRoutes: false,
exportPathMap() {
return {
'/main': { page: '/main' }
}
}
}
})
})
)
2 changes: 1 addition & 1 deletion renderer/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import App from 'next/app'
import 'antd/dist/antd.less'
import 'antd/dist/antd.css'

export default class IMApp extends App {
componentDidCatch(error: any, errorInfo: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import classnames from 'classnames'
import React from 'react'
import store from '../../../store/editorStore'
import useSubscribe from '../../../../../../hooks/useSubscribe'
import './index.less'
import useDrag from '../../../RightPanel/useDrag'
import './index.less'

interface Hover {
props: {}
Expand Down
5 changes: 3 additions & 2 deletions renderer/pages/main/Editor/LeftPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import MonacoEditor from './MonacoEditor'
import Preview from './Preview'
import Editor from './Editor'
import { Button, Input, DatePicker, Tabs } from 'antd'

import './index.less'
import css from './index.less'

const { TabPane } = Tabs

function LeftPanel() {
console.log('css', css)

return (
<div className='LeftPanel'>
<Tabs tabBarStyle={{ margin: 0 }} animated={false} defaultActiveKey='0'>
Expand Down
14 changes: 7 additions & 7 deletions renderer/pages/main/MainHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import SearchInput from './SearchInput'
import UserAvatar from './UserAvatar'
import './index.less'
import $style from './index.less'

export default class MainHeader extends React.Component {
render() {
return (
<div className='MainHeader'>
render() {
return (
<div className={$style.MainHeader}>
<SearchInput />
<UserAvatar />
</div>
)
}
</div>
)
}
}
8 changes: 4 additions & 4 deletions renderer/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Layout, Menu, Icon } from 'antd'
import MainHeader from './MainHeader'
import Setting from './Setting'
import Editor from './Editor'
import './index.less'
import $style from './index.less'
import logo from './images/Icon.png'

const { Content, Sider } = Layout
Expand Down Expand Up @@ -44,7 +44,7 @@ class LayoutComponent extends React.Component {
defaultCollapsed={true}
collapsed={this.state.collapsed}
onCollapse={this.onCollapse}>
<div className='ant-pro-sider-menu-logo' id='logo'>
<div className={$style['ant-pro-sider-menu-logo']} id='logo'>
<img src={logo} alt='logo' />
</div>
<Menu
Expand All @@ -63,9 +63,9 @@ class LayoutComponent extends React.Component {
</Menu>
</Sider>
<Layout>
<div className='mainLayout'>
<div className={$style.mainLayout}>
<MainHeader></MainHeader>
<div className='mainContent'>
<div className={$style.mainContent}>
{menuKey === '1' && <Editor />}
{menuKey === '5' && <Setting />}
</div>
Expand Down

0 comments on commit fa04cac

Please sign in to comment.