Skip to content

Commit

Permalink
chore: Migrate from kkt 4.x to 5.x #17
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jan 3, 2020
1 parent c363f8b commit 00c4d3b
Show file tree
Hide file tree
Showing 6 changed files with 7,304 additions and 2,704 deletions.
64 changes: 22 additions & 42 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,56 +1,36 @@
{
"presets": [
[
"@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions", "ie >= 10"]
}
}
],
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-async-to-generator",
["@babel/plugin-proposal-object-rest-spread", { "loose": true, "useBuiltIns": true }],
[
"@babel/plugin-transform-runtime",
{
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}
]
],
"env": {
"esm": {
"presets": [
"cjs": {
"plugins": [
[
"@babel/preset-env",
{
"modules": false
}
"babel-plugin-transform-remove-imports",
{ "test": "(less|css)$" }
]
],
]
},
"esm": {
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"useESModules": true
}
],
"babel-plugin-transform-rename-import",
{ "original": "^(.+?)\\.less$", "replacement": "$1.css" }
]
]
},
"cjs": {
"plugins": [
"esm:dev": {
"presets": [
"@babel/preset-react",
[
"babel-plugin-transform-remove-imports",
"@tsbb/babel-preset-tsbb",
{
"test": "(less|css)$"
"modules": false,
"targets": {
"browsers": [ "last 2 versions" ]
},
"transformRuntime": {
"useESModules": true
}
}
],
]
]
}
}
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules
dist
build
lib
cjs
esm
!src/lib
npm-debug.log*
.DS_Store
Expand Down
98 changes: 36 additions & 62 deletions .kktrc.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,40 @@
const path = require('path');
const pkg = require('./package.json');
import path from 'path';

process.env.APPSRC = path.resolve(process.cwd(), 'website');
export const loaderOneOf = [
require.resolve('@kkt/loader-less')
];

module.exports = {
plugins: [
require.resolve('@kkt/plugin-less'),
],
babelInclude: [path.resolve(process.cwd(), 'src')],
// Modify the webpack config
config: (conf, { dev, env }, webpack) => {
if (env === 'prod') {
conf = {
...conf,
optimization: {
...conf.optimization,
// https://webpack.js.org/plugins/split-chunks-plugin/
splitChunks: {
chunks: 'async',
minSize: 30000,
minChunks: 2,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
}
};
}
// 获取 React CodeMirror 版本
conf.plugins.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
})
);
// 解析 Markdown 文件
conf.module.rules = [
...conf.module.rules,
{
test: /\.md$/,
loader: 'raw-loader',
},
];
export const moduleScopePluginOpts = [
path.resolve(process.cwd(), 'README.md')
];

if (env === 'prod') {
// 生产模式下更改的 webpack 配置
conf.entry[0] = path.resolve(process.cwd(), 'website');
conf.output.publicPath = '';
} else {
conf.entry[1] = path.resolve(process.cwd(), 'website', 'index.js');
export default (conf, opts, webpack) => {
const pkg = require(path.resolve(process.cwd(), 'package.json'));
// Webpack parses md file text
conf.module.rules.map((item) => {
if (item.oneOf) {
item.oneOf.unshift({
test: /\.md$/,
use: require.resolve('raw-loader'),
});
}
return conf;
},
};
return item;
});

// Get the project version.
conf.plugins.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
})
);
// 解析 Markdown 文件
conf.module.rules = [
...conf.module.rules,
{
test: /\.md$/,
loader: 'raw-loader',
},
];
conf.output = { ...conf.output, publicPath: './' }
return conf;
}
Loading

0 comments on commit 00c4d3b

Please sign in to comment.