jetpacker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +11 -11
- data/.node-version +1 -0
- data/.rubocop.yml +125 -0
- data/.travis.yml +54 -5
- data/CHANGELOG.jetpacker.md +7 -0
- data/CHANGELOG.md +1000 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +157 -21
- data/MIT-LICENSE +20 -0
- data/README.md +671 -16
- data/Rakefile +8 -3
- data/docs/assets.md +119 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +253 -0
- data/docs/deployment.md +130 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +200 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +137 -0
- data/docs/troubleshooting.md +156 -0
- data/docs/typescript.md +126 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +364 -0
- data/docs/yarn.md +23 -0
- data/gemfiles/Gemfile-rails-edge +12 -0
- data/gemfiles/Gemfile-rails.4.2.x +9 -0
- data/gemfiles/Gemfile-rails.5.0.x +9 -0
- data/gemfiles/Gemfile-rails.5.1.x +9 -0
- data/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/jetpacker.gemspec +28 -22
- data/lib/install/angular.rb +23 -0
- data/lib/install/bin/webpack +18 -0
- data/lib/install/bin/webpack-dev-server +18 -0
- data/lib/install/binstubs.rb +4 -0
- data/lib/install/coffee.rb +25 -0
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +72 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpack/development.js +5 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +5 -0
- data/lib/install/config/webpack/test.js +5 -0
- data/lib/install/config/webpacker.yml +96 -0
- data/lib/install/elm.rb +39 -0
- data/lib/install/erb.rb +25 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +55 -0
- data/lib/install/examples/elm/hello_elm.js +16 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/babel.config.js +87 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/react/tsconfig.json +20 -0
- data/lib/install/examples/stimulus/application.js +1 -0
- data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/lib/install/examples/typescript/tsconfig.json +23 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +72 -0
- data/lib/install/javascript/packs/application.js +18 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +25 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +11 -0
- data/lib/install/loaders/vue.js +6 -0
- data/lib/install/react.rb +18 -0
- data/lib/install/stimulus.rb +12 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +55 -0
- data/lib/install/typescript.rb +46 -0
- data/lib/install/vue.rb +49 -0
- data/lib/jetpacker/version.rb +2 -1
- data/lib/tasks/installers.rake +37 -0
- data/lib/tasks/webpacker.rake +28 -0
- data/lib/tasks/webpacker/binstubs.rake +11 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clean.rake +21 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +43 -0
- data/lib/tasks/webpacker/info.rake +20 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +13 -0
- data/lib/tasks/webpacker/yarn_install.rake +21 -0
- data/lib/webpacker.rb +46 -0
- data/lib/webpacker/commands.rb +50 -0
- data/lib/webpacker/compiler.rb +107 -0
- data/lib/webpacker/configuration.rb +113 -0
- data/lib/webpacker/dev_server.rb +66 -0
- data/lib/webpacker/dev_server_proxy.rb +31 -0
- data/lib/webpacker/dev_server_runner.rb +72 -0
- data/lib/webpacker/env.rb +39 -0
- data/lib/webpacker/helper.rb +176 -0
- data/lib/webpacker/instance.rb +37 -0
- data/lib/webpacker/manifest.rb +118 -0
- data/lib/webpacker/railtie.rb +98 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +4 -0
- data/lib/webpacker/webpack_runner.rb +32 -0
- data/package.json +82 -0
- data/package/__tests__/config.js +55 -0
- data/package/__tests__/dev_server.js +43 -0
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +46 -0
- data/package/__tests__/production.js +29 -0
- data/package/__tests__/staging.js +29 -0
- data/package/__tests__/test.js +26 -0
- data/package/config.js +37 -0
- data/package/config_types/__tests__/config_list.js +118 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +75 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/dev_server.js +20 -0
- data/package/env.js +19 -0
- data/package/environments/__tests__/base.js +74 -0
- data/package/environments/base.js +166 -0
- data/package/environments/development.js +51 -0
- data/package/environments/production.js +79 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +24 -0
- data/package/rules/babel.js +21 -0
- data/package/rules/css.js +3 -0
- data/package/rules/file.js +20 -0
- data/package/rules/index.js +20 -0
- data/package/rules/module.css.js +3 -0
- data/package/rules/module.sass.js +8 -0
- data/package/rules/node_modules.js +24 -0
- data/package/rules/sass.js +8 -0
- data/package/utils/__tests__/deep_assign.js +32 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/get_style_rule.js +65 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +22 -0
- data/package/utils/get_style_rule.js +45 -0
- data/package/utils/helpers.js +58 -0
- data/package/utils/objectify.js +3 -0
- data/test/command_test.rb +33 -0
- data/test/compiler_test.rb +75 -0
- data/test/configuration_test.rb +108 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/dev_server_test.rb +47 -0
- data/test/env_test.rb +23 -0
- data/test/helper_test.rb +142 -0
- data/test/manifest_test.rb +42 -0
- data/test/rake_tasks_test.rb +69 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/bin/webpack +14 -0
- data/test/test_app/bin/webpack-dev-server +14 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +12 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +97 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +31 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +33 -0
- data/test/webpack_runner_test.rb +51 -0
- data/test/webpacker_test.rb +13 -0
- data/yarn.lock +8321 -0
- metadata +267 -29
- data/.rspec +0 -3
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/jetpacker.rb +0 -6
@@ -0,0 +1,166 @@
|
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
3
|
+
|
4
|
+
const {
|
5
|
+
basename, dirname, join, relative, resolve
|
6
|
+
} = require('path')
|
7
|
+
const { sync } = require('glob')
|
8
|
+
const extname = require('path-complete-extname')
|
9
|
+
|
10
|
+
const webpack = require('webpack')
|
11
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
12
|
+
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
13
|
+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
14
|
+
const PnpWebpackPlugin = require('pnp-webpack-plugin')
|
15
|
+
|
16
|
+
const { isNotObject, prettyPrint } = require('../utils/helpers')
|
17
|
+
const deepMerge = require('../utils/deep_merge')
|
18
|
+
|
19
|
+
const { ConfigList, ConfigObject } = require('../config_types')
|
20
|
+
const rules = require('../rules')
|
21
|
+
const config = require('../config')
|
22
|
+
|
23
|
+
const getLoaderList = () => {
|
24
|
+
const result = new ConfigList()
|
25
|
+
Object.keys(rules).forEach((key) => result.append(key, rules[key]))
|
26
|
+
return result
|
27
|
+
}
|
28
|
+
|
29
|
+
const getPluginList = () => {
|
30
|
+
const result = new ConfigList()
|
31
|
+
result.append(
|
32
|
+
'Environment',
|
33
|
+
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(process.env)))
|
34
|
+
)
|
35
|
+
result.append('CaseSensitivePaths', new CaseSensitivePathsPlugin())
|
36
|
+
result.append(
|
37
|
+
'MiniCssExtract',
|
38
|
+
new MiniCssExtractPlugin({
|
39
|
+
filename: 'css/[name]-[contenthash:8].css',
|
40
|
+
chunkFilename: 'css/[name]-[contenthash:8].chunk.css'
|
41
|
+
})
|
42
|
+
)
|
43
|
+
result.append(
|
44
|
+
'Manifest',
|
45
|
+
new WebpackAssetsManifest({
|
46
|
+
integrity: false,
|
47
|
+
entrypoints: true,
|
48
|
+
writeToDisk: true,
|
49
|
+
publicPath: config.publicPathWithoutCDN
|
50
|
+
})
|
51
|
+
)
|
52
|
+
return result
|
53
|
+
}
|
54
|
+
|
55
|
+
const getExtensionsGlob = () => {
|
56
|
+
const { extensions } = config
|
57
|
+
return extensions.length === 1 ? `**/*${extensions[0]}` : `**/*{${extensions.join(',')}}`
|
58
|
+
}
|
59
|
+
|
60
|
+
const getEntryObject = () => {
|
61
|
+
const result = new ConfigObject()
|
62
|
+
const glob = getExtensionsGlob()
|
63
|
+
const rootPath = join(config.source_path, config.source_entry_path)
|
64
|
+
const paths = sync(join(rootPath, glob))
|
65
|
+
paths.forEach((path) => {
|
66
|
+
const namespace = relative(join(rootPath), dirname(path))
|
67
|
+
const name = join(namespace, basename(path, extname(path)))
|
68
|
+
result.set(name, resolve(path))
|
69
|
+
})
|
70
|
+
return result
|
71
|
+
}
|
72
|
+
|
73
|
+
const getModulePaths = () => {
|
74
|
+
const result = new ConfigList()
|
75
|
+
result.append('source', resolve(config.source_path))
|
76
|
+
if (config.resolved_paths) {
|
77
|
+
config.resolved_paths.forEach((path) => result.append(path, resolve(path)))
|
78
|
+
}
|
79
|
+
result.append('node_modules', 'node_modules')
|
80
|
+
return result
|
81
|
+
}
|
82
|
+
|
83
|
+
const getBaseConfig = () => new ConfigObject({
|
84
|
+
mode: 'production',
|
85
|
+
output: {
|
86
|
+
filename: 'js/[name]-[contenthash].js',
|
87
|
+
chunkFilename: 'js/[name]-[contenthash].chunk.js',
|
88
|
+
hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
|
89
|
+
path: config.outputPath,
|
90
|
+
publicPath: config.publicPath
|
91
|
+
},
|
92
|
+
|
93
|
+
resolve: {
|
94
|
+
extensions: config.extensions,
|
95
|
+
plugins: [PnpWebpackPlugin]
|
96
|
+
},
|
97
|
+
|
98
|
+
resolveLoader: {
|
99
|
+
modules: ['node_modules'],
|
100
|
+
plugins: [PnpWebpackPlugin.moduleLoader(module)]
|
101
|
+
},
|
102
|
+
|
103
|
+
node: {
|
104
|
+
dgram: 'empty',
|
105
|
+
fs: 'empty',
|
106
|
+
net: 'empty',
|
107
|
+
tls: 'empty',
|
108
|
+
child_process: 'empty'
|
109
|
+
}
|
110
|
+
})
|
111
|
+
|
112
|
+
module.exports = class Base {
|
113
|
+
constructor() {
|
114
|
+
this.loaders = getLoaderList()
|
115
|
+
this.plugins = getPluginList()
|
116
|
+
this.config = getBaseConfig()
|
117
|
+
this.entry = getEntryObject()
|
118
|
+
this.resolvedModules = getModulePaths()
|
119
|
+
}
|
120
|
+
|
121
|
+
splitChunks(callback = null) {
|
122
|
+
let appConfig = {}
|
123
|
+
const defaultConfig = {
|
124
|
+
optimization: {
|
125
|
+
// Split vendor and common chunks
|
126
|
+
// https://twitter.com/wSokra/status/969633336732905474
|
127
|
+
splitChunks: {
|
128
|
+
chunks: 'all',
|
129
|
+
name: false
|
130
|
+
},
|
131
|
+
// Separate runtime chunk to enable long term caching
|
132
|
+
// https://twitter.com/wSokra/status/969679223278505985
|
133
|
+
runtimeChunk: true
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
if (callback) {
|
138
|
+
appConfig = callback(defaultConfig)
|
139
|
+
if (isNotObject(appConfig)) {
|
140
|
+
throw new Error(`
|
141
|
+
${prettyPrint(appConfig)} is not a valid splitChunks configuration.
|
142
|
+
See https://webpack.js.org/plugins/split-chunks-plugin/#configuration
|
143
|
+
`)
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
return this.config.merge(deepMerge(defaultConfig, appConfig))
|
148
|
+
}
|
149
|
+
|
150
|
+
toWebpackConfig() {
|
151
|
+
return this.config.merge({
|
152
|
+
entry: this.entry.toObject(),
|
153
|
+
|
154
|
+
module: {
|
155
|
+
strictExportPresence: true,
|
156
|
+
rules: [{ parser: { requireEnsure: false } }, ...this.loaders.values()]
|
157
|
+
},
|
158
|
+
|
159
|
+
plugins: this.plugins.values(),
|
160
|
+
|
161
|
+
resolve: {
|
162
|
+
modules: this.resolvedModules.values()
|
163
|
+
}
|
164
|
+
})
|
165
|
+
}
|
166
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
const webpack = require('webpack')
|
2
|
+
const Base = require('./base')
|
3
|
+
const devServer = require('../dev_server')
|
4
|
+
const { outputPath: contentBase, publicPath } = require('../config')
|
5
|
+
|
6
|
+
module.exports = class extends Base {
|
7
|
+
constructor() {
|
8
|
+
super()
|
9
|
+
|
10
|
+
if (devServer.hmr) {
|
11
|
+
this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin())
|
12
|
+
this.config.output.filename = '[name]-[hash].js'
|
13
|
+
}
|
14
|
+
|
15
|
+
this.config.merge({
|
16
|
+
mode: 'development',
|
17
|
+
cache: true,
|
18
|
+
devtool: 'cheap-module-source-map',
|
19
|
+
output: {
|
20
|
+
pathinfo: true
|
21
|
+
},
|
22
|
+
devServer: {
|
23
|
+
clientLogLevel: 'none',
|
24
|
+
compress: devServer.compress,
|
25
|
+
quiet: devServer.quiet,
|
26
|
+
disableHostCheck: devServer.disable_host_check,
|
27
|
+
host: devServer.host,
|
28
|
+
port: devServer.port,
|
29
|
+
https: devServer.https,
|
30
|
+
hot: devServer.hmr,
|
31
|
+
contentBase,
|
32
|
+
inline: devServer.inline,
|
33
|
+
useLocalIp: devServer.use_local_ip,
|
34
|
+
public: devServer.public,
|
35
|
+
publicPath,
|
36
|
+
historyApiFallback: {
|
37
|
+
disableDotRule: true
|
38
|
+
},
|
39
|
+
headers: devServer.headers,
|
40
|
+
overlay: devServer.overlay,
|
41
|
+
stats: {
|
42
|
+
entrypoints: false,
|
43
|
+
errorDetails: true,
|
44
|
+
modules: false,
|
45
|
+
moduleTrace: false
|
46
|
+
},
|
47
|
+
watchOptions: devServer.watch_options
|
48
|
+
}
|
49
|
+
})
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
const TerserPlugin = require('terser-webpack-plugin')
|
2
|
+
const CompressionPlugin = require('compression-webpack-plugin')
|
3
|
+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
4
|
+
const safePostCssParser = require('postcss-safe-parser')
|
5
|
+
const Base = require('./base')
|
6
|
+
|
7
|
+
module.exports = class extends Base {
|
8
|
+
constructor() {
|
9
|
+
super()
|
10
|
+
|
11
|
+
this.plugins.append(
|
12
|
+
'Compression',
|
13
|
+
new CompressionPlugin({
|
14
|
+
filename: '[path].gz[query]',
|
15
|
+
algorithm: 'gzip',
|
16
|
+
cache: true,
|
17
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
18
|
+
})
|
19
|
+
)
|
20
|
+
|
21
|
+
if ('brotli' in process.versions) {
|
22
|
+
this.plugins.append(
|
23
|
+
'Compression Brotli',
|
24
|
+
new CompressionPlugin({
|
25
|
+
filename: '[path].br[query]',
|
26
|
+
algorithm: 'brotliCompress',
|
27
|
+
cache: true,
|
28
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
29
|
+
})
|
30
|
+
)
|
31
|
+
}
|
32
|
+
|
33
|
+
this.plugins.append(
|
34
|
+
'OptimizeCSSAssets',
|
35
|
+
new OptimizeCSSAssetsPlugin({
|
36
|
+
parser: safePostCssParser,
|
37
|
+
map: {
|
38
|
+
inline: false,
|
39
|
+
annotation: true
|
40
|
+
}
|
41
|
+
})
|
42
|
+
)
|
43
|
+
|
44
|
+
this.config.merge({
|
45
|
+
devtool: 'source-map',
|
46
|
+
stats: 'normal',
|
47
|
+
bail: true,
|
48
|
+
optimization: {
|
49
|
+
minimizer: [
|
50
|
+
new TerserPlugin({
|
51
|
+
parallel: true,
|
52
|
+
cache: true,
|
53
|
+
sourceMap: true,
|
54
|
+
terserOptions: {
|
55
|
+
parse: {
|
56
|
+
// Let terser parse ecma 8 code but always output
|
57
|
+
// ES5 compliant code for older browsers
|
58
|
+
ecma: 8
|
59
|
+
},
|
60
|
+
compress: {
|
61
|
+
ecma: 5,
|
62
|
+
warnings: false,
|
63
|
+
comparisons: false
|
64
|
+
},
|
65
|
+
mangle: {
|
66
|
+
safari10: true
|
67
|
+
},
|
68
|
+
output: {
|
69
|
+
ecma: 5,
|
70
|
+
comments: false,
|
71
|
+
ascii_only: true
|
72
|
+
}
|
73
|
+
}
|
74
|
+
})
|
75
|
+
]
|
76
|
+
}
|
77
|
+
})
|
78
|
+
}
|
79
|
+
}
|
data/package/index.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
3
|
+
|
4
|
+
const { resolve } = require('path')
|
5
|
+
const { existsSync } = require('fs')
|
6
|
+
const Environment = require('./environments/base')
|
7
|
+
const loaders = require('./rules')
|
8
|
+
const config = require('./config')
|
9
|
+
const devServer = require('./dev_server')
|
10
|
+
const { nodeEnv } = require('./env')
|
11
|
+
|
12
|
+
const createEnvironment = () => {
|
13
|
+
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
14
|
+
const constructor = existsSync(path) ? require(path) : Environment
|
15
|
+
return new constructor()
|
16
|
+
}
|
17
|
+
|
18
|
+
module.exports = {
|
19
|
+
config,
|
20
|
+
devServer,
|
21
|
+
environment: createEnvironment(),
|
22
|
+
Environment,
|
23
|
+
loaders
|
24
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
const { join, resolve } = require('path')
|
2
|
+
const { cache_path: cachePath, source_path: sourcePath, resolved_paths: resolvedPaths } = require('../config')
|
3
|
+
const { nodeEnv } = require('../env')
|
4
|
+
|
5
|
+
// Process application Javascript code with Babel.
|
6
|
+
// Uses application .babelrc to apply any transformations
|
7
|
+
module.exports = {
|
8
|
+
test: /\.(js|jsx|mjs)?(\.erb)?$/,
|
9
|
+
include: [sourcePath, ...resolvedPaths].map((p) => resolve(p)),
|
10
|
+
exclude: /node_modules/,
|
11
|
+
use: [
|
12
|
+
{
|
13
|
+
loader: 'babel-loader',
|
14
|
+
options: {
|
15
|
+
cacheDirectory: join(cachePath, 'babel-loader-node-modules'),
|
16
|
+
cacheCompression: nodeEnv === 'production',
|
17
|
+
compact: nodeEnv === 'production'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const { join } = require('path')
|
2
|
+
const { source_path: sourcePath, static_assets_extensions: fileExtensions } = require('../config')
|
3
|
+
|
4
|
+
module.exports = {
|
5
|
+
test: new RegExp(`(${fileExtensions.join('|')})$`, 'i'),
|
6
|
+
use: [
|
7
|
+
{
|
8
|
+
loader: 'file-loader',
|
9
|
+
options: {
|
10
|
+
name(file) {
|
11
|
+
if (file.includes(sourcePath)) {
|
12
|
+
return 'media/[path][name]-[hash].[ext]'
|
13
|
+
}
|
14
|
+
return 'media/[folder]/[name]-[hash:8].[ext]'
|
15
|
+
},
|
16
|
+
context: join(sourcePath)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const babel = require('./babel')
|
2
|
+
const file = require('./file')
|
3
|
+
const css = require('./css')
|
4
|
+
const sass = require('./sass')
|
5
|
+
const moduleCss = require('./module.css')
|
6
|
+
const moduleSass = require('./module.sass')
|
7
|
+
const nodeModules = require('./node_modules')
|
8
|
+
|
9
|
+
// Webpack loaders are processed in reverse order
|
10
|
+
// https://webpack.js.org/concepts/loaders/#loader-features
|
11
|
+
// Lastly, process static files using file loader
|
12
|
+
module.exports = {
|
13
|
+
file,
|
14
|
+
css,
|
15
|
+
sass,
|
16
|
+
moduleCss,
|
17
|
+
moduleSass,
|
18
|
+
nodeModules,
|
19
|
+
babel
|
20
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
const { join } = require('path')
|
2
|
+
const { cache_path: cachePath } = require('../config')
|
3
|
+
const { nodeEnv } = require('../env')
|
4
|
+
|
5
|
+
// Compile standard ES features for JS in node_modules with Babel.
|
6
|
+
// Regex details for exclude: https://regex101.com/r/SKPnnv/1
|
7
|
+
module.exports = {
|
8
|
+
test: /\.(js|mjs)$/,
|
9
|
+
include: /node_modules/,
|
10
|
+
exclude: /(?:@?babel(?:\/|\\{1,2}|-).+)|regenerator-runtime|core-js|^webpack$|^webpack-assets-manifest$|^webpack-cli$|^webpack-sources$|^@rails\/webpacker$/,
|
11
|
+
use: [
|
12
|
+
{
|
13
|
+
loader: 'babel-loader',
|
14
|
+
options: {
|
15
|
+
babelrc: false,
|
16
|
+
presets: [['@babel/preset-env', { modules: false }]],
|
17
|
+
cacheDirectory: join(cachePath, 'babel-loader-node-modules'),
|
18
|
+
cacheCompression: nodeEnv === 'production',
|
19
|
+
compact: false,
|
20
|
+
sourceMaps: false
|
21
|
+
}
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|